3

I have a reverse proxy set up in nginx for a node.js server.

server {
    listen 80;

    server_name sub.domain.tld;

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

It works all fine and dandy, however, I only want sub.domain.tld to work. Opening up domain.tld in a browser still routes to the node.js server.

1 Answer 1

6

try to add this

server {
    listen 80;
    server_name domain.tld;
    return 404;
}
2
  • 1
    This worked, and I expanded my problem/solution to include other subdomains. server_name ~^(.*)?.?domain.tld;. Doesn't seem as elegant of a solution, though.
    – dook
    May 3, 2014 at 19:18
  • But this will allow all subdomains right? hello.domain.tld fake.domain.tld Is there any way to allow only one subdomain ? Sep 23, 2022 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.