我为所有不匹配的连接设置了一个 nginx 网络服务器,其中包含一些虚拟主机和一个默认主机(返回 444;)。
如果我尝试访问我的一个虚拟主机,我仍然会得到 444。
这是我的 nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
ssl_protocols TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384';
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
upstream php-handler {
server unix:/run/php/php7.0-fpm.sock;
}
server_tokens off;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
在/etc/nginx/sites-enabled/default中:
server {
listen 80 default_server;
listen 443 default_server;
server_name _;
return 444;
access_log off; log_not_found off;
}
在/etc/nginx/sites-enabled/测试:
server {
listen 80;
listen [::]:80;
server_name <mydomain.com>;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name <mydomain.com>;
ssl on;
ssl_certificate /etc/acme.sh/<....>/fullchain.cer;
ssl_certificate_key /etc/acme.sh/<....>/<...>.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://....:8080;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 0;
}
}
有什么想法可以让它工作吗?顺便说一句:如果我删除默认的,我就可以访问我的虚拟主机。
非常感谢
答案1
好的,我找到解决方案了。
我忘记在默认文件中定义 SSL 证书。添加自签名证书后,它就可以正常工作了。