LoginSignup
15
15

More than 5 years have passed since last update.

指定していないserver_nameのとき404を出すようにする

Posted at

nginxは最初に定義されたserver directiveをデフォルトとして, server_nameがマッチしなかった時は勝手にそこを見る.
この挙動で嬉しい思いをしたことがあまりない.

nginx.conf
  server {
    listen 80 default_server;
    location / {
       return 404;
       break;
    }
  }

nginx.confの最初にこれを入れておくと無駄にハマらない

15
15
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
15
15