以下設定在所有 80 port virtual host 當 server_name 都不符合時,會回應 444。
server { listen 80 default_server; server_name _; return 444; }
若也要設定 https 預設網站,當 server_name 都不符合時,
亦會回應 444,可增加監聽 443 port,雖然是回應 444,但還是需要設定 SSL 憑證。
所以先產生憑證 (若沒/etc/nginx/ssl資料夾,可先自行建立)
$ openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/nginx/ssl/default_server.key -out /etc/nginx/ssl/default_server.crt填完資料,即可產生憑證。
nginx 設定如下
sserver { listen 80 default_server; listen 443 default_server ssl; server_name _; ssl_certificate /etc/nginx/ssl/default_server.crt; ssl_certificate_key /etc/nginx/ssl/default_server.key; return 444; }
參考:
http://nginx.org/en/docs/http/server_names.html
listen 語法,http://nginx.org/en/docs/http/ngx_http_core_module.html
listen address[:port] [default_server] [ssl] [http2 | spdy] [proxy_protocol] [setfib=number] [fastopen=number] [backlog=number] [rcvbuf=size] [sndbuf=size] [accept_filter=filter] [deferred] [bind] [ipv6only=on|off] [reuseport] [so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]];
listen port [default_server] [ssl] [http2 | spdy] [proxy_protocol] [setfib=number] [fastopen=number] [backlog=number] [rcvbuf=size] [sndbuf=size] [accept_filter=filter] [deferred] [bind] [ipv6only=on|off] [reuseport] [so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]];
listen unix:path [default_server] [ssl] [http2 | spdy] [proxy_protocol] [backlog=number] [rcvbuf=size] [sndbuf=size] [accept_filter=filter] [deferred] [bind] [so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]];
沒有留言:
張貼留言