0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

nginxでルートドメインにリクエストが来たときだけ外部にリダイレクトしたい

Last updated at Posted at 2022-06-12

あまりないと思いますが……
サブドメインでも同じような設定をすると応用できそうです。知らんけど。

状況

  • sub.example.comにアクセスされたらそのままsub.example.comを開く
  • example.comにアクセスされたらexample.jpにリダイレクトする

設定

ルートドメインに関係する設定ファイルにlocation ~ ^/$でよしなに。

server {
     listen 443 ssl http2;
     listen [::]:443 ssl http2;
 
     server_name example.com;
     location ~ ^/$ {
              return 301 https://example.jp/;
     }
}

参考資料

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?