Handle www to non-www redirect.
A secundary `server` block has been added. It'll listen on the `www` host and redirect to the `non-www` host.
This commit is contained in:
parent
dc91fd4862
commit
804f8c4e54
|
@ -87,14 +87,28 @@ http {
|
||||||
# You should use virtual hosts and move these `server` blocks in their own
|
# You should use virtual hosts and move these `server` blocks in their own
|
||||||
# file inside a `sites-available` folder. Then symink back to `sites-enabled`
|
# file inside a `sites-available` folder. Then symink back to `sites-enabled`
|
||||||
# to activate.
|
# to activate.
|
||||||
|
|
||||||
|
# www to non-www redirect -- duplicate content is BAD:
|
||||||
|
# https://github.com/h5bp/html5-boilerplate/blob/5370479476dceae7cc3ea105946536d6bc0ee468/.htaccess#L362
|
||||||
|
# Choose between www and non-www, listen on the *wrong* one and redirect to
|
||||||
|
# the right one -- http://wiki.nginx.org/Pitfalls#Server_Name
|
||||||
|
server {
|
||||||
|
# don't forget to tell on which port this server listens
|
||||||
|
listen 80;
|
||||||
|
# listen on the www host
|
||||||
|
server_name www.example.com
|
||||||
|
# and redirect to the non-www host (declared below)
|
||||||
|
return 301 $scheme://example.com$request_uri;
|
||||||
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
# listen 80 default_server deferred; # for Linux
|
# listen 80 default_server deferred; # for Linux
|
||||||
# listen 80 default_server accept_filter=httpready; # for FreeBSD
|
# listen 80 default_server accept_filter=httpready; # for FreeBSD
|
||||||
listen 80 default_server;
|
listen 80 default_server;
|
||||||
|
|
||||||
# e.g. "localhost" to accept all connections, or "www.example.com"
|
# listen on the non-www host -- the www-host is declared above and redirects
|
||||||
# to handle the requests for "example.com" (and www.example.com)
|
# here
|
||||||
# server_name www.example.com;
|
server_name example.com;
|
||||||
|
|
||||||
# Path for static files
|
# Path for static files
|
||||||
root /sites/example.com/public;
|
root /sites/example.com/public;
|
||||||
|
|
Loading…
Reference in New Issue