咨询这里是否遇到了跨域问题?
来源:3-9 Nginx作为静态资源web服务_跨域访问场景配置
慕村1342571
2019-01-03
Jeson老师:
为了真实性,个人申请了外网服务地址及相应的域名,并对服务器的nginx进行了配置,在服务器上做了ssl设置,通过https://cross.zhaoy6.com/的cross.html 中的ajax请求去访问http://app.zhaoy6.com/下的文件crosscheck.html,测试文件如下
https://cross.zhaoy6.com/cross.html
http://app.zhaoy6.com/crosscheck.html
上述两个文件单独都可以访问,个人觉得这个应该算是一个跨域访问的场景。
但是无法复现老师的情况,出现另一个错误Provisional headers are shown ,查了一下网上的个人分析是请求没有提交出去,最近做前后端分离的项目涉及到nginx配置ssl,前端用react后端用springboot也遇到类似问题烦请老师帮助
2回答
-
慕村1342571
提问者
2019-01-04
解决了其中的一部分问题,由于配置了两个站点(2份配置文件),则允许跨域访问是指,若从A域跨到B域访问资源,需要对B区域的配置文件进行修改,修改A域的配置文件就不起效果:
set $origin80 'A域地址'; #写入需要跨域的请求地址
add_header 'Access-Control-Allow-Origin' $origin80;
add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,OPTIONS';
碰到另一个问题,如果B域是以https协议发起的请求到A域的,而A域是http协议访问,则会出现如下问题:
00 -
慕村1342571
提问者
2019-01-03
ssl部分的配置:
server {
listen 443 ssl;
#server_name 198.13.35.89 app.zhaoy6.com;
server_name cross.zhaoy6.com;
keepalive_timeout 100;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_certificate /etc/nginx/conf.d/ssl_key/zhaoy6.crt;
ssl_certificate_key /etc/nginx/conf.d/ssl_key/zhaoy6.key;
#ssl_certificate_key /etc/nginx/conf.d/ssl_key/zhaoy6_nopass.key;
sendfile on;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html/cross;
#random_index on;
}
location ~ .*\.(jpg|gif|png)$ {
gzip on;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css aplication/xml text/javascript application/x-httpd-php images/jpeg image/gif image/png;
root /usr/share/nginx/html/images;
}
location ~ .*\.(txt|xml)$ {
gzip on;
gzip_http_version 1.1;
gzip_comp_level 1;
gzip_types text/plain application/javascript application/x-javascript text/css aplication/xml text/javascript application/x-httpd-php images/jpeg image/gif image/png;
root /usr/share/nginx/html/doc;
}
location ~ .*\.(htm|html)$ {
#add_header Access-Control-Allow-Origin https://cross.zhaoy6.com;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
root /usr/share/nginx/html/cross;
}
location ~ ^/download {
gzip_static on;
tcp_nopush on;
root /usr/share/nginx/html/download;
}
location ~ ^/desk {
root /usr/share/nginx/html/address/desk;
index index.html index.htm;
}
location ~ ^/mobile {
root /usr/share/nginx/html/address/mobile;
index index.html index.htm;
}
}
022019-01-04
相似问题