Report this

What is the reason for this report?

Multiple ports on nginx

Posted on February 21, 2017

I have my main site successfully running with https proxy to my localhost:5000.

I need to also route websocket traffic from mydomain:4000 to localhost:4001.

I can’t get this to work with nginx. I don’t get any build errors, but my websocket can’t connect.

Here is my sites-default file:

Default server configuration

server { listen 80; listen [::]:80 default_server ipv6only=on; return 301 https://$host$request_uri; }

server{ listen 4000; listen [::]:4000; server_name app.mydomain.com;

location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; proxy_pass https://localhost:4001/; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection “upgrade”; proxy_set_header Host $host; }

}

HTTPS — proxy all requests to the Node app

server { # Enable HTTP/2 listen 443 ssl http2; listen [::]:443 ssl http2; server_name app.mydomain.com;

# Use the Let’s Encrypt certificates
ssl_certificate /etc/letsencrypt/live/app.mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/app.mydomain.com/privkey.pem;

Include the SSL configuration from cipherli.st

include snippets/ssl-params.conf;

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass https://localhost:5000/;
    proxy_ssl_session_reuse off;
    proxy_set_header Host $http_host;
    proxy_cache_bypass $http_upgrade;
    proxy_redirect off;
    proxy_http_version 1.1;
 proxy_set_header Upgrade $http_upgrade;
 proxy_set_header Connection "upgrade";
proxy_set_header Host $host;

} }



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

hi @josh2633520652c0fb3db80b1c do you figure out the problem i think i have the same issue

@oska have you got solution for the same issue?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.