Configure my NGINX web server to host a Node.js application via reverse proxy?

Answered
itsbambi asked this question 1 year, 5 months ago
itsbambi on Jan 4, 2022

I'm trying to configure my Ubuntu server to host my Node.js application via NGINX. My Node.js application is currently running on localhost port 8080.

Right now, my NGINX file has the default contents:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }
}

How do I update this configuration file to host my Node.js application via reverse proxy?

1 suggested answers
looper003 on Jan 13, 2022

You'll need to update the location {} section of your configuration file.

Update the content of your NGINX configuration file to this:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                proxy_pass http://localhost:8080;
                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;
        }
}
0 replies
Answered