Nginx no-www to www and www to no-www

前端 未结 17 2189
予麋鹿
予麋鹿 2020-11-22 09:53

I am using nginx on Rackspace cloud following a tutorial and having searched the net and so far can\'t get this sorted.

I want www.mysite.com to go to mysite.com as

17条回答
  •  盖世英雄少女心
    2020-11-22 09:53

    If you are having trouble getting this working, you may need to add the IP address of your server. For example:

    server {
    listen XXX.XXX.XXX.XXX:80;
    listen XXX.XXX.XXX.XXX:443 ssl;
    ssl_certificate /var/www/example.com/web/ssl/example.com.crt;
    ssl_certificate_key /var/www/example.com/web/ssl/example.com.key;
    server_name www.example.com;
    return 301 $scheme://example.com$request_uri;
    }
    

    where XXX.XXX.XXX.XXX is the IP address (obviously).

    Note: ssl crt and key location must be defined to properly redirect https requests

    Don't forget to restart nginx after making the changes:

    service nginx restart
    

提交回复
热议问题