技术解析
问题(目的):同一服务器下,并存 java 和 node 项目,nginx 实现不同路径转发不同端口 希望的结果是:访问:fashion.goonie.cn/api/wxpay/ 和访问:fashion.goonie.cn:8080/wxpay/ 应该是一样的 我的配置:
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
upstream java{
server fashion.xxxx.cn:8080;
}
upstream node{
server fashion.xxxx.cn:3001;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location ^~ /api/ {
proxy_pass http://java;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Remote_add美国服务器r $remote_addr;
}
location /* {
proxy_pass http://node;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Remote_addr $remote_addr;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
希望的结果是:访问:fashion.xxxx.cn/api/wxpay/ 和访问:fashion.xxxx.cn:8080/wxpay/ 应该是一样的。 但是现在 fashion.xxxx.cn/api/wxpay/ 访问失败