nginxnginx-reverse-proxylinode

React Router 7 SSR app with Node.js on Linode with Nginx


I have an SSR React Router 7 (framework version) Node.js/Express application that I am trying to wire up to a domain, which is running through Linode. I set up my domain on Linode, and updated nameservers on my domain's registrar to point to Linode.

My RR7 application (living on my Linode Ubuntu 24.04 LTS machine) runs fine, but whenever I npm start the app, for example, to test that I can access it through my domain, the domain only shows the nginx welcome startup page, and only if I go to www.mydomain.com:3000 then it does show my app, which does in fact run on port 3000, which makes sense. Just not sure why it’s not working when going directly to mydomain.com.

Here is my nginx config file:

server {
    listen 80;
    server_name mydomain.com;

    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;
    }
}

I've tested the nginx config and restarted the nginx server, but still can't get this to work. Forgive me if this is not enough info, I just didn't want to add too much to the OP, so if more info is needed, will provide. Thanks!


Solution

  • Ok, looks I figured it out. In the /etc/nginx/sites-enabled directory, the default config file was overriding my app/domain nginx config. I'm unsure why, perhaps because of the default_server option on the listen config (no idea if that's why), but disabling that default config got my site to load directly at mydomain.com without needing to specify the port.

    Thanks for your help @Ivan Shatsky!