How to change the port of a nginx reverse proxy from 80 to 3001

August 3, 2018 833 views
Nginx Node.js Ubuntu 16.04

my setup consists of a node App serving a Rest Api. This Api operates on localhost:3000. To publish it, i want to reverse proxy this api with the port 3001. How is this possible in nginx.

Here is my first try, that doesnt work.

server {
        listen 3001;
        listen [::]:3001;

        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;


         location / {
              proxy_pass http://localhost:3000;
              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;


Be the first one to answer this question.