简体   繁体   中英

How to prevent nginx from responding on a specific subdomain

I have a website (with a slightly naughty name), and I'd like to have a dedicated ssh subdomain, in which there would be no website, but I can use for ssh. How do I prevent nginx from serving my website on this domain? As a side question, how do I deny ssh access to the base domain?

How do I prevent nginx from serving my website on this domain?

I typically set up the default server to be IP-based and return 404, then add vhosts for the specific domains I want:

server {
    listen *:80 default_server;
    return 404;
}
server {
    listen *:80;
    server_name bar.com;
    ...
}

Then, even if you have other subdomains pointing to the same IP, no web pages will be served for them.

As a side question, how do I deny ssh access to the base domain?

Unless you have two different IP addresses, putting your SSH on a subdomain isn't going to accomplish much because SSH doesn't have the concept of vhosts. Ie, the two domains will point to the same IP and the SSH service will listen for all connections on that IP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM