Skip to content

Instantly share code, notes, and snippets.

@scottwb
Created January 25, 2011 16:38
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save scottwb/795176 to your computer and use it in GitHub Desktop.
Save scottwb/795176 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.
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...
}
}
@Quasaur
Copy link

Quasaur commented Jul 30, 2014

i notice that there's no root statement...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment