Nginx Remove WWW And Respond To Both

前端 未结 6 1811
粉色の甜心
粉色の甜心 2020-12-29 21:53

I have the following nginx configuration fragment:

server {
   listen 80;

   server_name mydomain.io;

   root /srv/www/domains/mydomain.io;

   index index         


        
6条回答
  •  死守一世寂寞
    2020-12-29 22:13

    According to https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#server-name-if, you should use:

    server {
      server_name www.example.com;
      return 301 $scheme://example.com$request_uri;
    }
    server {
      server_name example.com;
      # [...]
    }
    

提交回复
热议问题