-
-
Save chrisevans/1128389 to your computer and use it in GitHub Desktop.
Nginx config to route domain and subdomains, except for explicit virtual hosts, to the www subdomain.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http { | |
# Default virtual host for www.example.com. This will pick up all HTTP | |
# requests to port 80 that are not for one of the other virtual hosts. | |
server { | |
listen 80; | |
server_name www.example.com; | |
# ...your server config here... | |
if ($host != 'www.example.com') { | |
rewrite ^ http://www.example.com$request_uri? permanent; | |
} | |
location / { | |
# ...your own config here... | |
} | |
} | |
# Virtual host for test.example.com. | |
server { | |
listen 80; | |
server_name test.example.com; | |
# ...your server config here... | |
} | |
# Virtual host for staging.example.com. | |
server { | |
listen 80; | |
server_name staging.example.com; | |
# ...your server config here... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not working for me