最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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: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.

Here is my nginx config file:

server {
    listen 80;
    server_name mydomain;

    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. Five 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!

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: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.

Here is my nginx config file:

server {
    listen 80;
    server_name mydomain;

    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. Five 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!

Share Improve this question edited Mar 6 at 4:41 Drew Reese 204k18 gold badges245 silver badges273 bronze badges asked Mar 6 at 3:57 LushmoneyLushmoney 52012 silver badges28 bronze badges 6
  • Are you sure your config is included in your nginx configuration? Did you see it when running the nginx -T command? Did you check mydomain, www.mydomain, or both? The config you've shown won't work for the www.mydomain domain since you didn't list it in the server names list, so the default server block will be used for it (see the How Nginx processes a request documentation page). – Ivan Shatsky Commented Mar 6 at 7:05
  • The nginx configuration file seems to be correct from what I’ve seen in docs, and yes the nginx -t command does come back successful. I tried adding www.mydomain in addition to mydomain to the server_name block in the config file, but still not working properly. – Lushmoney Commented Mar 6 at 11:20
  • 1 Yes, your configuration seems to be correct. However nginx -t and nginx -T are two different commands. The first one only checks the configuration file for correctness, while the second additionally outputs the full configuration as nginx sees it. Run nginx -T to see if your configuration snippet is really included in the full configuration used by nginx. – Ivan Shatsky Commented Mar 6 at 11:59
  • Oh gotcha, good call. And yes, running nginx -T does show the configuration I set up for this app/domain... – Lushmoney Commented Mar 6 at 13:42
  • 1 Receiving an nginx welcome page means some other server block is answering your request, but I didn't have any ideas how to debug further, sorry. A silly question, did you reload nginx after adding this configuration? – Ivan Shatsky Commented Mar 6 at 14:00
 |  Show 1 more comment

1 Answer 1

Reset to default 0

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 without needing to specify the port.

Thanks for your help @Ivan Shatsky!

发布评论

评论列表(0)

  1. 暂无评论