Question

Nginx subdomain and domain multiple server name configuration

I’m trying to configure multiple server block in nginx but stuck at getting one endpoint working, below is my first site setup and it’s working :

server {
    listen 80;

    server_name app.example.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;
    }
}

my subdomain file located at

home/app/index.html

Then I want to do for the another one, I add a folder call site means it host my static site at example.com

server {
    listen 80;

    server_name example.com;

    location /site {
        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;
    }
}

my main domain file located at

home/site/index.html

I got a bad gateway 502 error.


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello @ryanpq and all, is this thread still monitored? I’m having a lot of trouble getting my sub domain up and running after getting SSL and all the other tutorials I followed have threads that are no longer monitored. Support is not really offering me any help either. I’m getting the 502 error, everything works fine for my primary domain and it’s using the exact same setup (they’re both using the same node app - obviously proxied to a different port on localhost and I changed the server name). If you’re there please let me know and I’ll post my server blocks, any help would be awesome!!

The second configuration you created does not handle requests for example.com. It only routes traffic directed at example.com/site to your directory. The location line specifies a location relative to the document root in the request. You should either add a root to route other requests to static files or change location /site to location /