0

I am having trouble doing something so simple...

I have a service on my server that I configured to use a particular hostname which I have mapped with an A record. However I want to return a 403 error when this subdomain is accessed with a browser.

But it does not seem to work. I just followed the same steps I used to disallow web traffic from going to the ip address directly.

server {
    listen  80;
    server_name     155.155.155.155;
    return  403;
}

This worked fine but when I do this

server {
    listen  80;
    server_name     service.mydomain.com;
    return  403;
}

It doesn't 403. It just goes to the Nginx test page.

What would be the elegant solution for doing something like this?

Steve
  • 1

1 Answers1

0

If the request for service.mydomain.com goes to a nginx site test there must be an other vhost that matches the server name first, e.g., *.mydomain.com or a vhost acting as default_server. Check your config and remove that one. Change your default vhost to

server {
    listen  80   default_server;
    return  403;
}

That way not only direct access to your IP but to any vhost that is not explicitly set will be rejected, e.g. requests to *.mydomain.com or to otherdomain.com.

xblax
  • 316
  • 2
  • 7