简体   繁体   中英

Nginx + NodeJS redirecting to port 80

I am having issues redirecting my port 80 to 4000 where my nodejs application is running on my Digital Ocean Ubuntu Droplet. Here is my /etc/nginx/sites-available/default file:

server {
    listen 80;

    server_name my_site.com;

    location / {
        proxy_pass http://MY_IP_ADDRESS:4000;
        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;
    }
}

When ever I head over to my droplet's IP on port 4000 the application loads successfully but not when I try on port 80.

You are doing a proxy_pass of port :8080 but you said your application is running on port 4000. You need to tell nginx the correct port to proxy, (4000 instead of 8080)

Then you need to restart the nginx service sudo service nginx restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM