本文标题:《「备忘」Nginx 重定向(301)相关》。
镜像链接:https://www.wdssmq.com/post/20140819797.html
环境基于https://lnmp.org/脚本构建;
环境基于https://lnmp.org/脚本构建;
LNMP 网站配置路径:
/usr/local/nginx/conf/vhost/
然后编辑域名.conf文件;
根域名跳转到 www:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| server { listen 443 ssl http2; server_name www.wdssmq.com feed.wdssmq.com wdssmq.com;
# …………
# 一般在 server_name 下边,自己找合适的位置 if ($host = 'wdssmq.com' ) { rewrite ^/(.*)$ https://www.wdssmq.com/$1 permanent; }
# 如有伪静态规则,则放在这里 location / { if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php) { rewrite (.*) $1/index.php; } if (!-f $request_filename) { rewrite (.*) /index.php; } }
# ………… }
|
另外的写法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| server { listen 443 ssl http2; server_name demo.wdssmq.com zbp17.wdssmq.com;
# …………
# 一般在 server_name 下边,自己找合适的位置 if ($host != 'demo.wdssmq.com' ) { rewrite ^/(.*)$ http://demo.wdssmq.com/$1 permanent; }
# 如有伪静态规则,则放在这里 location / { # ………… }
# ………… }
|
其他配置:
1 2 3 4 5 6 7 8 9
| # 一般和伪静态规则在一起并放在伪静态规则之前 location / { # 自动添加结尾斜杠 if (!-f $request_filename) { rewrite ^/([^\.]+[^/])$ $scheme://$host/$1$2/ permanent; } # ………… }
|
然后重启 nginx
1 2
| /usr/local/nginx/sbin/nginx -s reload
|
下边命令为重启 lnmp
相关推荐:
「折腾」Nginx 解析网址参数并跳转_电脑网络_沉冰浮水
「备忘」LNMPA 伪静态/301 相关_电脑网络_沉冰浮水
「笔记」LNMP 部署/续期 SSL 证书_电脑网络_沉冰浮水
「备忘」Nginx 重定向(301)相关_电脑网络_沉冰浮水 「当前」
「笔记」.htaccess 及 nginx.conf 可用变量一览_电脑网络_沉冰浮水