[英]node nginx proxy on multiple ports, same domain not working
I have setup reverse proxy for ngnix for the node app running 8042 and I want to do the same for admin app running on 8043 and it is simply not working, Couldn't find the issue.我已经为运行 8042 的节点应用程序设置了 ngnix 的反向代理,我想为运行在 8043 上的管理应用程序做同样的事情,但它根本不起作用,找不到问题。
This works,这有效,
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
rewrite ^/proj(.*) /$1 break;
proxy_pass http://localhost:8042;
}
}
This doesn't, both code exists on same sites-available/default file这不是,两个代码都存在于同一个站点可用/默认文件中
server {
listen 8881 default_server;
server_name _;
location /proj-admin {
rewrite ^/proj-admin(.*) /$1 break;
proxy_pass http://localhost:8043;
}
}
Replace your current nginx.conf file in the /etc/nginx folder with the following,将 /etc/nginx 文件夹中当前的 nginx.conf 文件替换为以下内容,
#worker_processes 2;
events {
worker_connections 1024;
}
http {
sendfile on;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
log_format timed_combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$request_time $upstream_response_time $pipe';
access_log /var/log/nginx/access.log timed_combined;
error_log /var/log/nginx/error.log;
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream api_server {
server 127.0.0.1:8042;
}
upstream admin_server {
server 127.0.0.1:8043;
}
server {
listen 80;
server_name _;
return 404;
}
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass http://api_server;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
location /proj-admin {
proxy_pass http://admin_server;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
that one work with me那个和我一起工作
...
location /api/ {
rewrite /api/(.*)$ /$1 break;
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.