1、将所有的http请求转暖换为带www的https请求
server {
listen [::]:80;
listen 80;
server_name yourdomain.com www.yourdomain.com;
# redirect http to https www
return 301 https://www.yourdomain.com$request_uri;
}
server {
listen [::]:443 ssl http2;
listen 443 ssl http2;
server_name www.yourdomain.com;
# SSL code
# other code
}
2、将不带www的http/htts的请求转换为带www的https请求
server {
listen [::]:80;
listen 80;
server_name yourdomain.com www.yourdomain.com;
# redirect http to https www
return 301 https://www.yourdomain.com$request_uri;
}
server {
listen [::]:443 ssl http2;
listen 443 ssl http2;
server_name yourdomain.com;
# SSL code
# redirect https non-www to https www
return 301 https://www.yourdomain.com$request_uri;
}
server {
listen [::]:443 ssl http2;
listen 443 ssl http2;
server_name www.yourdomain.com;
# SSL code
# other code
}
3、将带www的http/htts的请求转换为不带www的https请求
server {
listen [::]:80;
listen 80
server_name yourdomain.com www.yourdomain.com;
# redirect http to https non-www
return 301 https://yourdomain.com$request_uri;
}
server {
listen [::]:443 ssl http2;
listen 443 ssl http2;
server_name www.yourdomain.com;
# SSL code
# redirect https non-www to https www
return 301 https://yourdomain.com$request_uri;
}
server {
listen [::]:443 ssl http2;
listen 443 ssl http2;
server_name yourdomain.com;
# SSL code
# Other code
}
在Nginx中,怎么把http全转发为https
最新推荐文章于 2024-05-17 13:43:54 发布