Skip to content

Instantly share code, notes, and snippets.

@chrisevans
Forked from scottwb/nginx_subdomain.conf
Created August 5, 2011 20:08
Show Gist options
  • Save chrisevans/1128389 to your computer and use it in GitHub Desktop.
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.
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...
}
}
@pprathameshmore
Copy link

Not working for me

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