简体   繁体   English

多个端口上的节点 nginx 代理,同一个域不起作用

[英]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.

相关问题 如何使用nginx proxy_pass和Node Express获得多个端口? - How do you get multiple ports working with nginx proxy_pass and Node Express? 在同一域上使用 nginx 为多个节点应用程序提供服务 - Serving multiple node apps with nginx on same domain 运行 nginx 来提供文件并充当同一域上 Node 应用程序的反向代理 - Running nginx to serve files and act as a reverse proxy for Node app on same domain Nginx 反向代理对域名不起作用 - Nginx reverse proxy not working on domain name NGINX:使用1个域名为多个端口设置SSL证书 - NGINX: Setup SSL Certificate for multiple ports using 1 domain name Nginx 到 node.js 的反向代理不起作用 - Nginx reverse proxy to node.js not working 使用Nginx反向代理隐藏一个域上的Node应用程序端口号 - Hiding Node app port numbers on one domain with nginx reverse proxy 如何配置nginx从多个端口重定向到同一应用程序? - How to configure nginx to redirect to same app from multiple ports? 多个位置的 NGINX 反向代理不起作用 - NGINX reverse proxy for multiple locations not working 如何托管具有相同域但路径不同的多个网站,例如:domain.fr/siteA、domain.fr/siteB、/siteC 与 docker 和 nginx 反向代理 - How to host multiple website with same domain but different path ex: domain.fr/siteA, domain.fr/siteB, /siteC with docker and nginx reverse proxy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM