Welcome! Log In Create A New Profile

Advanced

Undeclared subdomain redirecting to last declared subdomain

Posted by Windlord 
Undeclared subdomain redirecting to last declared subdomain
May 21, 2011 06:46PM
Hello Nginx users.

I was setting up my first Nginx server a few moments ago, and found a very strange problem.
Just to let you all know, I have set a wildcard A-record for my domain and therefore all subdomains point towards my Nginx server.
I have several subdomains set up for my own purposes and have them all declared in the following way:

server_name subdomain.domain.tld;
root /var/www/domain/subdomain/public_html;

under a server { declaration for each of them.

My problem is that, even if I have only declared sd1.domain.tld and sd2.domain.tld, Nginx will always show the contents of sd3.domain.tld with the content being that of the last declared subdomain which in this case would be sd2.domain.tld.
I would expect a non-declared subdomain to not show anything at all and return an error or a 404 page.

Has anyone encountered such a problem and if so what is the solution?
I have searched online but have not found a solution so far.

Thank you in advance!
Re: Undeclared subdomain redirecting to last declared subdomain
May 23, 2011 03:54AM
Problem solved.
It seems that one has to set a default server by declaring:

listen 80 default_server;

This seems a bit odd though.
nginx should not choose a random server to redirect all stray requests to by default...
Re: Undeclared subdomain redirecting to last declared subdomain
June 15, 2011 06:13AM
Glad that your problem is solved
Re: Undeclared subdomain redirecting to last declared subdomain
July 21, 2011 05:06AM
would anyone mind sharing a nice default vhost?
I am hitting the same problem over here.

issue is that mydomain.tld and www.mydomain.tld are the only ones needed.
since I am lacking a default vhost, ANY subdomain will work so xxd.mydomain.tld works :-(

what should one do with non-existing sub-domains? redirect to main domain? rewrite? how?
Re: Undeclared subdomain redirecting to last declared subdomain
July 21, 2011 05:24AM
found my solution here: http://nginx.org/en/docs/http/converting_rewrite_rules.html

I jsut added another server declaration to my one and only vhost to redirect to the main domain.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 86
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready