设置www.github.icu
强制跳转github.icu
域名,首先保证www.github.icu
和github.icu
解析到同一个IP地址:
其次修改nginx配置文件中的server_name部分,新增如下判断:
if ($host ~* www.github.icu) {
rewrite ^(.*)$ https://github.icu$1 permanent;
}
之后使用nginx -s reload
重载nginx配置即可。
注意:因为我是80强制跳转443,故以上判断只需要在443上添加即可,其他情况酌情参考修改:
server {
listen 443 ssl;
server_name github.icu;
if ($host ~ "\d+\.\d+\.\d+\.\d") {
return https://github.icu;
}
if ($host ~* www.github.icu) {
rewrite ^(.*)$ https://github.icu$1 permanent;
}
ssl_certificate /etc/nginx/ssl/github.icu.pem;
ssl_certificate_key /etc/nginx/ssl/github.icu.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
...
“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill
标 题:nginx设置301重定向