2022年1月
有的时候我们往往只是因为自己的一点小失误(粗心)而前功尽弃,没那么严重的情况下也可能会折腾而耽误不少时间
location /mxz {
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,PATCH,OPTIONS;
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
return 204;
}
proxy_pass http://49.233.205.96:8815;
rewrite ^.+mxz/?(.*)$ /$1 break;
add_header Access-Control-Allow-Origin $http_origin always;
add_header Access-Control-Allow-Methods *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
这样一段配置,本身是从之前的配置中拷贝过来修改了一下转发规则,但是拷贝的时候因为终端显示的时候自动换行了,直接用鼠标覆盖的方式去复制,结果导致复制后的配置换行,重启nginx并不报错,但这样配置出来的路径竟然出现了跨域问题。在vim模式下编辑这个配置文件,完全感觉不到区别,一个是自动换行了,一个是拷贝后多了一个换行符。
location /mxz {
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,PATCH,OPTIONS;
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-
With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
return 204;
}
proxy_pass http://49.233.205.96:8815;
rewrite ^.+mxz/?(.*)$ /$1 break;
add_header Access-Control-Allow-Origin $http_origin always;
add_header Access-Control-Allow-Methods *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,
If-Modified-Since,Cache-Control,Content-Type,Authorization';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}