亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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重載過。

https://img1.sycdn.imooc.com//5bf8c8150001f5e309480298.jpg

https://img1.sycdn.imooc.com//5bf8c8af00015b4b07090101.jpg

https://img1.sycdn.imooc.com//5bf8c8c5000174ae03950312.jpg




正在回答

3 回答

b.com:8888/test/get1

b.com:8888/test/get1

b.com后面加配置的監聽端口號


0 回復 有任何疑惑可以回復我~

同樣的問題,樓主解決了嗎 嗚嗚

0 回復 有任何疑惑可以回復我~

這跟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;

0 回復 有任何疑惑可以回復我~
#1

慕工程255496 提問者

還是不行.(http://wj.com/test/postJson)訪問不到后端
2018-11-27 回復 有任何疑惑可以回復我~
#2

慕工程255496 提問者

http://wj.com/ 是可以看到(Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com. Thank you for using nginx.)
2018-11-27 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

nginx配置后,訪問不到后端,報404

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號