我有多个域名和多个使用SSL证书运行在Nginx下的域名。 所有的域基本上都使用完全相同的configuration,取代当然的名字,除了我有SSL设置指定的启用HTTPS的域。 在这两个域之间,configuration对于SSL来说也是一样的,除了密钥等的文件名之外。 每个网站也运行在自己的专用IP上。 (他们全部)
我所有的非SSL网站都工作得很好。 我可以访问他们没有任何问题。 我的所有SSL站点都从CloudFlare获得521错误。 (严格的SSL开启,只是fyi)
我之前build立的一个领域工作得很好。 即使我删除了另一个启用了SSL的域,它现在仍然不起作用。 我所做的唯一configuration更改是添加一个也使用SSL证书的新域。 当我用nginxtestingconfiguration时,它表示一切正常。 当我检查netstat时,我可以看到443的监听IP。我在/ var / log / syslog或nginx的访问和错误日志中看不到任何错误。
主要是nginx.conf
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
在/etc/nginx/conf.d中configuration示例SSL站点
server { listen [IPv6 address]:443; server_name domain; ssl on; ssl_certificate /etc/nginx/domain.crt; ssl_certificate_key /etc/nginx/domain.key; ssl_session_cache shared:SSL:10m; ssl_session_timeout 5m; ssl_protocols TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; add_header Strict-Transport-Security max-age=31536000; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /srv/domain/www; index index.html index.htm index.php; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { # root html; fastcgi_pass unix:/run/domain.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /srv/domain/www$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
好吧,这就是问题的结局。 我认为,如果您启用了完全SSL(严格),CloudFlare将始终通过HTTPS连接到您的网站。 显然这不是它的工作原理。 如果您尝试使用HTTP访问站点,CloudFlare仍将通过HTTP连接到您的服务器。
我所要做的只是在每个域上添加一个页面规则来强制redirect到HTTPS。
所以这根本就不是nginx,只是我愚蠢。