Change default page for subdomain?

Abe Miessler asked:

I am trying to add a subdomain and I would like it to display a different default page than my site would without a subdomain. So mysite.com displays index.html by default. I would like sub.mysite.com to display sub.html.

I am able to get my nginx server to handle the subdomain requests with the setup below:

server {
        listen 80;
        server_name mysite.com www.mysite.com sub.mysite.com;

But it just goes to the default page for the main site. How can I tell nginx that if the subdomain is used it needs to return a specific HTML file?

My answer:


Create a new server block for your new subdomain.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.