以下是以discuz论坛为例
server
{
listen 80;
server_name wenrouge.com ;
if ($host != 'www.wenrouge.com' ) {
rewrite ^/(.*)$ http://www.wenrouge.com/$1 permanent;
}
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot;
include discuz.conf;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log off;
}
注意:关键的地方是
server_name wenrouge.com ;
if ($host != 'www.wenrouge.com' ) {
rewrite ^/(.*)$ https://www.wenrouge.com/$1 permanent;
}
server_name wenrouge.com ;
if ($host = 'wenrouge.com' ) {
rewrite ^/(.*)$ https://www.wenrouge.com/$1 permanent;
}