0

I have multiple node.js apps running (through pm2) on different ports (8000, 8200, 8300) of a single server using the http protocol.

Now to enable https support I installed nginx and wrote config for redirecting incoming traffic on port 8200 to the localhost's port 8200 (likewise for ports 8000 and 8300) but it causes nginx to crash with the error: nginx: [emerg] bind() to [::]:8200 failed (98: Address already in use)

Following is my nginx config:

server {
        listen 8200 ssl;
        server_name <redacted>;
        ssl_certificate /certs/<redacted>.cer;
        ssl_certificate_key /certs/<redacted>.key;
        error_page 497 301 =307 https://$host:$server_port$request_uri;
        location / {
            proxy_pass http://localhost:8200;
            proxy_redirect off;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Ssl on;
        }
}

I understand that port 8200 is already being used by pm2 but I want to redirect http traffic on those ports to https somehow.

m-ketan
  • 1,258
  • 2
  • 17
  • 23

1 Answers1

0

The problem is this line:

listen 8200 ssl;

You can't listen on the same port than your node app.

Servers, like nginx or your node app use sockets to listen to network datas. So even if it is on another network protocol they should listen to the socket. So, port SOULD be diffrents.

Alaindeseine
  • 3,260
  • 1
  • 11
  • 21