【发布时间】:2017-03-07 19:31:57
【问题描述】:
我希望流量转到https://example.com。 不允许使用 www 前缀,并且 需要 SSL。
我们遇到的问题是,许多(尽管不是全部)首次访问者在点击刷新之前不会被重定向到 HTTPS。
您是否在我的配置中看到任何允许这种行为的内容?
server {
listen 80;
listen 443 ssl;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 80;
listen 443 ssl;
server_name example.com;
root /var/www/html/mm;
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 https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $http_host;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
client_max_body_size 200m;
location / {
try_files $uri $uri/ /index.php?$query_string;
index index.php index.html index.htm install.php;
client_max_body_size 200m;
}
location ~ \.php$ {
try_files $uri /index.php =404;
#fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_pass php-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_param PHP_VALUE "upload_max_filesize = 150M \n upload_max_filesize=151M";
fastcgi_param PHP_VALUE "post_max_size = 150M \n post_max_size=151M";
include fastcgi_params;
}
【问题讨论】:
-
如果人们在没有
www.的情况下进入,你永远不会重定向 http -> https。刷新后,由于 HSTS 标头,它可以工作。 -
在第一个块中,
return 301 https://example.com$request_uri;是重定向。 -
是的,如果人们输入 with
www. -
请使用正确的配置添加答案,如果可行,我会给你功劳。
-
不确定它是否对未来的读者有帮助,因为它基本上归结为“这个问题是由一个无法再复制的问题或一个简单的印刷错误引起的。虽然类似的问题可能是在这里,这个问题的解决方式不太可能帮助未来的读者。这通常可以通过在发布之前识别并仔细检查重现问题所需的最短程序来避免。”
标签: ssl nginx https configuration