大网数据广告活动
服务器运维问答

nginx reverse proxy in subfolder resulted in "bad gateway" or "file not found"

· 52CE 我爱测

I am trying to put a node.js app (node-red) using a reverse proxy. server { listen 80; server_name example.com location / { proxy_pass http://example.com:1880; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy…

问题原文

原帖链接 · Leonard AB · CC BY-SA 4.0

I am trying to put a node.js app (node-red) using a reverse proxy.

server {
listen 80;

server_name example.com

            location / {
                proxy_pass http://example.com:1880;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
            }
}

This one worked as expected, I could access node-red from example.com

Then I need to use the root example.com for a homepage, and move node-red into a subfloder.

server {
listen 80;

server_name example.com

    location / {
            root     /home/admin/nginx/www;
            index    index.html;

        }
    location /nodered/ {
                proxy_pass http://example.com:1880;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
            }
}

For this attempt, I could access the homepage (index.html) when accessing example.com, but when accessing example.com/node-red I got Bad Gateway error

I also tried to change location /nodered/ into location /nodered(/.*)$ following this answer, but then I got 404 error.

Can anybody help? thanks.

已采纳解答

原帖链接 · Leonard AB · CC BY-SA 4.0

It turns out that I made a silly mistake.
The problem is in the trailing slash. The code below solved the problem

proxy_pass http://example.com:1880/;

Thank you to this answer.

Btw, I am not sure why the documentation shows no trailing slash though.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-12-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。