沉冰浮水

沉冰浮水

做最终到的事,成为最终成为的人!
github
bilibili
mastodon
zhihu
douban

「メモ」Nginx リダイレクト(301)関連

タイトル:「メモ」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

関連記事:

「折腾」Nginx 解析网址参数并跳转_电脑网络_沉冰浮水

「备忘」LNMPA 伪静态 / 301 相关_电脑网络_沉冰浮水

「笔记」LNMP 部署 / 续期 SSL 证书_电脑网络_沉冰浮水

「备忘」Nginx 重定向(301)相关_电脑网络_沉冰浮水 「現在」

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。