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.