目前的问题是 http://example.com 可以正常跳转到 https://example.com ,而直接访问 http://www.example.com chrome 接下载空文件,safari 则无法访问。
请教下各位大佬如何解决 www 这个跳转 https 的问题?
另外有关 http 跳转 https 还有更简洁的配置方法吗?
nginx version: nginx/1.20.1
配置如下:
server
{
listen 80 http2;
server_name example.com wwww.example.com;
return 301 https://$server_name$request_uri;
# rewrite ^(.*)$ https://$host$1 permanent;
location ~ /
{
root /home/wwwroot/serverhome;
index index.html index.htm;
}
}
server
{
listen 443 ssl http2;
server_name example.com www.example.com;
ssl_certificate /usr/local/nginx/ssl/example.com.crt;
ssl_certificate_key /usr/local/nginx/ssl/example.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
root /home/wwwroot/serverhome;
index index.htm index.html;
access_log /home/wwwlogs/example.com.log main;
}
请教下各位大佬如何解决 www 这个跳转 https 的问题?
另外有关 http 跳转 https 还有更简洁的配置方法吗?
nginx version: nginx/1.20.1
配置如下:
server
{
listen 80 http2;
server_name example.com wwww.example.com;
return 301 https://$server_name$request_uri;
# rewrite ^(.*)$ https://$host$1 permanent;
location ~ /
{
root /home/wwwroot/serverhome;
index index.html index.htm;
}
}
server
{
listen 443 ssl http2;
server_name example.com www.example.com;
ssl_certificate /usr/local/nginx/ssl/example.com.crt;
ssl_certificate_key /usr/local/nginx/ssl/example.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
root /home/wwwroot/serverhome;
index index.htm index.html;
access_log /home/wwwlogs/example.com.log main;
}