ポートとホスト名の組み合わせを 1 つだけリッスンし、他のすべてのリクエストで 404 を返す方法を見つける必要があります。
私の例:
SSL を使用し、ポート 443 ではなくポート 12345 をリッスンする owncloud のサブドメインをセットアップしました。このサブドメインが oc.example.com であると仮定します。したがって、nginx はhttps://oc.example.com:12345のみをリッスンし、リッスンしないよう にしたい
- http://oc.example.com:12345 _
- https://oc.example.com : Xここで X != 12345
- https:// BLABLA .example.com:12345
- http://IP.IP.IP.IP :12345
- https ://IP.IP.IP.IP:12345
- 等々
https://oc.example.com:12345と完全に一致しないリソースをリクエストすると、エラー (404 not found など) が返されるか、サーバーが応答しなくなります。
これまでの私の設定は次のようになります。
server {
# I think there's something wrong here?
listen 12345;
server_name oc.example.com;
ssl on;
ssl_certificate /etc/ssl/nginx/owncloud/owncloud.crt;
ssl_certificate_key /etc/ssl/nginx/owncloud/owncloud.key;
add_header Strict-Transport-Security max-age=31536000;
add_header X-Frame-Options DENY;
# Path to the root of your installation
root /var/some/path/to/my/owncloud/;
client_max_body_size 10G; # set max upload size
fastcgi_buffers 64 4K;
rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
index index.php;
error_page 403 = /core/templates/403.php;
error_page 404 = /core/templates/404.php;
... here are the definitions of my locations
}
ドキュメントを読んだところ、nginx は最初にポート番号で正しいサーバー定義を探すことがわかりました。複数の一致がある場合、正しい定義を見つけるために server_name が使用されます。しかし、私の定義は 1 つだけです。
誰かが問題を解決する方法を知っていますか?