尝试访问我的网站时Chrome Version 66.0.3359.139 (Official Build) (64-bit)
遇到以下错误:
尝试一下Firefox 60.0(64 bit)
,成功了!
我使用的nginx版本
nginx -V
nginx version: nginx/1.13.12
built by gcc 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)
built with OpenSSL 1.1.0f 25 May 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.13.12/debian/debuild-base/nginx-1.13.12=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'
卷曲给了我一个200 OK
curl -I https://v4tailor.com
HTTP/2 200
date: Sat, 12 May 2018 14:49:46 GMT
content-type: text/html; charset=UTF-8
set-cookie: __cfduid=d54d82d396e2f2bad73930fda4a6b883a1526136586; expires=Sun, 12-May-19 14:49:46 GMT; path=/; domain=.v4tailor.com; HttpOnly
cache-control: no-cache, private
strict-transport-security: max-age=31536000;
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 419db19f1d899a04-EWR
Nginx 配置。我使用 LetsEncrypt。
//nginx.conf
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
root /var/www/html;
index index.php;
server_name v4tailor.com www.v4tailor.com;
# SSL Certificates
ssl_certificate "/etc/letsencrypt/live/v4tailor.com/cert.pem";
ssl_certificate_key "/etc/letsencrypt/live/v4tailor.com/privkey.pem";
ssl_dhparam /etc/nginx/dhparam.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_session_cache shared:SSL:1m;
ssl_session_tickets off;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security "max-age=31536000;
#includeSubDomains" always;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
}
这一切都是从我切换到 LetsEncrypt 时开始的,最初我没有意识到这一点,因为我使用的所有浏览器都是在 Gecko 引擎上实现的,但是当我想向我的老板展示演示时,它令人尴尬地不起作用 -.-。
最初我只使用 Cloud-flare 进行 SSL。
我清除了缓存并尝试在 chrome://net-internals/events 上检查它。还在不同的机器上进行了测试。
由于其模糊性,谷歌搜索该错误非常困难。
使固定
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
root /var/www/html/main/public;
index index.php;
server_name v4tailor.com www.v4tailor.com;
# SSL Certificates
ssl_certificate "/etc/letsencrypt/live/v4tailor.com/cert.pem";
ssl_certificate_key "/etc/letsencrypt/live/v4tailor.com/privkey.pem";
ssl_dhparam /etc/nginx/dhparam.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_session_cache shared:SSL:1m;
ssl_session_tickets off;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security: max-age=31536000;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /render {
proxy_pass http://127.0.0.1:5000/render;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# optionally set the value of the environment variables used in the application
fastcgi_param APP_ENV prod;
fastcgi_param APP_SECRET 23kl86a56;
fastcgi_param DATABASE_URL "mysql://root:patriot356@@localhost:3306/v4tailor";
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
location /blog {
try_files $uri $uri/ /blog/index.php?$args;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
Firefox 忽略了标头错误,但 Chrome 停止了。感谢你们!!我想知道它到底是如何通过 Nginx 的配置测试的。这真是令人头疼。
答案1
我不确定这是否会导致问题,但配置的以下部分肯定是错误的:
add_header Strict-Transport-Security "max-age=31536000;
#includeSubDomains" always;
这将产生以下 HTTP 响应标头:
Strict-Transport-Security: max-age=31536000;
#includeSubDomains:
看来您忘记关闭配置中的引用,从而导致标头损坏。有些浏览器会忽略这种损坏的标头,有些则不会。