需求是:
1 、 http 的 www 和 @ 强制跳转到 https://example.com
2 、 https 的 www 也强制跳转到 https://example.com
现在完成了 1 ,看了半天 nginx ,也没搞明白 2 怎么实现
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
server
{
#listen 80;
listen 443 ssl http2;
#listen [::]:80;
ssl on;
ssl_certificate /usr/local/nginx/conf/example.crt;
ssl_certificate_key /usr/local/nginx/conf/example.key;
server_name example.com www.example.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/example.com;
include example.conf;
#error_page 404 /404.html;
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log off;
}
1 、 http 的 www 和 @ 强制跳转到 https://example.com
2 、 https 的 www 也强制跳转到 https://example.com
现在完成了 1 ,看了半天 nginx ,也没搞明白 2 怎么实现
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
server
{
#listen 80;
listen 443 ssl http2;
#listen [::]:80;
ssl on;
ssl_certificate /usr/local/nginx/conf/example.crt;
ssl_certificate_key /usr/local/nginx/conf/example.key;
server_name example.com www.example.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/example.com;
include example.conf;
#error_page 404 /404.html;
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log off;
}