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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.