【问题标题】:nginx nodejs+pm2 return connot GET /pm2nginx nodejs+pm2返回不能GET /pm2
【发布时间】:2016-08-02 23:45:21
【问题描述】:

我安装了 nginx 来为多个 nodejs 应用程序提供服务

在我的服务器上,我有 2 个应用程序 myapp 和 pm2-web

nginx 配置如下所示

http {
    # .... logs, gzip ... etc
    server {
        location / {
           proxy_pass http://localhost:5000;
           proxy_http_version 1.1;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection 'upgrade';
           proxy_set_header Host $host;
           proxy_cache_bypass $http_upgrade;
        }

        location /pm2 {
           proxy_pass http://localhost:9000;
           proxy_http_version 1.1;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection 'upgrade';
           proxy_set_header Host $host;
           proxy_cache_bypass $http_upgrade;
        }

    }

我的应用运行良好,但当我尝试访问 /pm2

我收到以下错误

Cannot GET /pm2

当 pm2-web 没有运行时,我得到 502 Bad Gateway

但我仍然可以从http://IP:9000 访问 pm2

【问题讨论】:

    标签: node.js nginx pm2


    【解决方案1】:

    URL 的 /pm2 部分正在传递到您的 Node 应用程序,它与任何路径都不匹配。

    即,您的 pm2 应用程序正在 9000 上运行,但您正在尝试访问不存在的 http://localhost:9000/pm2

    在您的代理传递 URL 中包含一个尾部斜杠,以确保不包含 /pm2

    location /pm2 {
       proxy_pass http://localhost:9000/;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection 'upgrade';
       proxy_set_header Host $host;
       proxy_cache_bypass $http_upgrade;
    }
    

    【讨论】:

    • rewrite ^/pm2(.*)$ $1 last; 我得到error 500rewrite ^/pm2(.*) /$1 break; 我得到pm2-web version {{version}}
    • 它返回pm2-web version {{version}} 我认为这是因为服务器找不到静态文件css|js ...等
    猜你喜欢
    • 2015-08-14
    • 2018-08-02
    • 2021-05-21
    • 1970-01-01
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 2019-07-13
    • 2020-09-30
    相关资源
    最近更新 更多