任何人都可以指出当我的Nginx服务器被要求提供其不知道的站点时,如何配置默认主机响应吗?我尝试过:
server {
listen 443 default_server;
listen [::]:443 default_server;
server_name _;
return 444;
}
这最终导致所有其他站点引起“意外关闭连接”错误。
请注意,我没有计划支持旧版https客户端(那些不了解SNI的客户端)。
我正在使用Nginx 1.14.0
答案 0 :(得分:0)
通过浏览Web,答案似乎是您需要创建一个自签名证书,然后将其应用于默认主机。没有人会相信这一点,但是鉴于它们以未处理的主机名结尾,这可能没有太大关系吗?
我按照Digital Ocean上的说明进行操作,这里将对其进行总结(太多内容无法包含全部内容):
生成dhparm文件(需要一段时间):
sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
默认主机的443配置:
server {
listen 443 default_server;
listen [::]:443 default_server;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
server_name _;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
ssi on;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
ssl-signed.conf文件内容:
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
ssl-params.conf文件内容:
# from https://cipherli.st/
# and https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
# Disable preloading HSTS for now. You can use the commented out header line that includes
# the "preload" directive if you understand the implications.
#add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
请注意,以上内容已通过Nginx 1.14.0进行了测试