我已将nginx配置为将http重定向到我的网站的https。这是我的配置块:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# ......
fastcgi_param HTTPS on;
fastcgi_param HTTP_SCHEME https;
root /var/www/example;
index index.php index index.html index.htm;
server_name www.example.com example.com;
location / {
try_files $uri $uri/ =404;
}
gzip on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
image/svg+xml;
gzip_vary on;
location ~* \.(jpg|jpeg|png|gif|ico|css|cur|js)$ {
expires 7d;
}
}
对于某些客户端,Http不会重定向到https,并且花费很长时间,而服务器没有响应。但是对于其他一些客户端,它将重定向!例如,它不适用于我的桌面浏览器,但可以通过移动浏览器访问时重定向很好。
这可以在nginx日志中找到,其中有499个错误代码,其中有不重定向的错误代码,有301个
当然,从https直接访问每个浏览器都可以正常工作。