Question

Nginx subdomain and domain multiple server name configuration

  • Posted March 1, 2016
  • Nginx

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.

Subscribe
Share

Submit an 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.

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 /