タイトル:「メモ」Nginx リダイレクト(301)に関する情報
日付:2021 年 11 月 14 日 11:02:08
タグ:
- LNMP
- Linux
- 301
- Nginx
カテゴリ: - コンピューターネットワーク
ID:2346
エイリアス:20140819797
環境はhttps://lnmp.org/
スクリプトに基づいて構築されています。
LNMP ウェブサイトの設定パス:
/usr/local/nginx/conf/vhost/
次に、ドメイン.conf
ファイルを編集します。
ルートドメインを www にリダイレクトする:
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;
}
}
# …………
}
別の方法:
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 / {
# …………
}
# …………
}
次に、Nginx を再起動します。
/usr/local/nginx/sbin/nginx -s reload
以下のコマンドで LNMP を再起動します。
/root/lnmp restart
関連記事:
「备忘」LNMPA 伪静态 / 301 相关_电脑网络_沉冰浮水