nginx配置后,訪問不到后端,報404
nginx配置:
server{
???listen?80;
??????server_name?wj.com;
???location?/{
????????proxy_pass?http://localhost:8080/;
???????
????????add_header?Access-Control-Allow-Origin?$http_origin;
????????add_header?Access-Control-Allow-Methods?*;
????????add_header?Access-Control-Max-Age?3600;
????????add_header?Access-Control-Allow-Credentials?true;
????????add_header?Access-Control-Allow-Headers?$http_access_control_request_headers;
???????
????????if?($request_method?=?OPTIONS){
?????????return?200;
????????}
??????}
???}client:
var?base?=?"http://wj.com/test";
nginx重載過。



2020-01-09
b.com:8888/test/get1
b.com:8888/test/get1
b.com后面加配置的監聽端口號
2018-12-14
同樣的問題,樓主解決了嗎 嗚嗚
2018-11-24
這跟nginx有關,即只有response code為以下value時,才add the specified field:
Adds the specified field to a response header provided that the response code equals 200, 201, 204, 206, 301, 302, 303, 304, or 307. A value can contain variables.
也就是說你本身的接口返回了404,導致add_header沒有生效,你可以通過這樣設置來讓nginx始終添加:
add_header Access-Control-Allow-Origin $http_origin always;