Skip to content

Instantly share code, notes, and snippets.

@AD7six
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AD7six/75f1638740c307fc6c50 to your computer and use it in GitHub Desktop.
Save AD7six/75f1638740c307fc6c50 to your computer and use it in GitHub Desktop.
root@h5bp:~# cat /etc/nginx/sites-enabled/nginx
server {
listen 80;
server_name ~^(www\.)(?<domain>.+)$;
return 301 $scheme://$domain$request_uri;
}
server {
listen 80 default_server;
return 301 $scheme://www.$host$request_uri;
}
root@h5bp:~# exit
logout
Connection to 10.10.10.12 closed.
andy@work:~$ curl -I -H "host: example.com" http://10.10.10.12/asdfasdf?foo=bar
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 17 Nov 2014 13:39:27 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: http://www.example.com/asdfasdf?foo=bar
andy@work:~$ curl -I -H "host: www.example.com" http://10.10.10.12/asdfasdf?foo=bar
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 17 Nov 2014 13:39:31 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: http://example.com/asdfasdf?foo=bar
andy@work:~$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment