我想从另一个源访问一个laravel 5.5 API端点https://foo.bar.com/api/v1.0/foo/bar
。因此我需要允许跨源请求。我已经将头添加到我的nginx配置中。但是我的浏览器仍然抱怨它不存在。这是我的nginx配置:
server {
listen *:443 ssl;
server_name foo.bar.com ;
ssl on;
ssl_certificate /etc/nginx/nxv_bhxwewp1idzm.crt;
ssl_certificate_key /etc/nginx/nxv_bhxwewp1idzm.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "...";
ssl_prefer_server_ciphers on;
client_max_body_size 1m;
index index.html index.htm index.php;
access_log /var/log/nginx/ssl-nxv_bhxwewp1idzm.access.log;
error_log /var/log/nginx/ssl-nxv_bhxwewp1idzm.error.log;
root /var/www/share/foo.bar.com;
location ~ ^/index\.php(/|$) {
set $path_info $fastcgi_path_info;
root /var/www/share/foo.bar.com/public/;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
try_files $uri $uri/ /index.php$is_args$args;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
add_header 'Access-Control-Allow-Origin' '*';
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location / {
root /var/www/share/foo.bar.com/public/;
try_files $uri $uri/ /index.php$is_args$args;
autoindex off;
index index.html index.php;
add_header 'Access-Control-Allow-Origin' '*';
}
sendfile off;
}
2条答案
按热度按时间sq1bmfud1#
我已经从@DigitalDrifter发布的链接中获取了信息。但似乎仅仅添加
Access-Control-Allow-Origin
还不足以让它工作。尽管我不关心访问方法等。所以这让交易生效了:tp5buhyn2#
将两行都添加到下面的文件中
/etc/nginx/可用站点/您的配置文件
并重新启动nginx服务器