nginx反向代理配置訪問后臺,基礎問題?
問題描述
報錯截圖如下:
XMLHttpRequest cannot load http://localhost:9090/services/user/login. Response to preflight request doesn’t pass access control check: No ’Access-Control-Allow-Origin’ header is present on the requested resource. Origin ’http://localhost:9000’ is therefore not allowed access. The response had HTTP status code 403.
反向代理配置如下:
請問,配置哪里出了問題?
問題解答
回答1:是跨域問題吧,參見/a/11...
回答2:server_name 用 localhost 就好,不必帶端口,不然 http://localhost:9090/services/ 就轉發到 9000 端口了。配置其他部分應該沒毛病,提一點建議,nginx配置也貼代碼而不是圖片就好了,謝謝。
server { listen 9090; server_name localhost; // 修改這里location /front/ {proxy_pass http://127.0.0.1:9000/; }location /services/ {proxy_pass http://127.0.0.1:8080/services/; }}回答3:
根據錯誤提示,應該是你的 Apache 沒有 services/ 目錄的訪問權限?是不是項目路徑不在 Apache 默認路徑下,是的話要做相應的配置
回答4:把location /services/ 改成 location /services
相關文章:
![css3 - [CSS] 動畫效果 3D翻轉bug](http://www.cgvv.com.cn/attached/image/news/202304/110831f073.png)