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
最新推荐文章于 2023-07-02 08:47:50 发布
本文介绍如何通过Nginx配置文件实现不同HTTP请求到HTTPS的重定向, 包括将所有http请求转换为https请求、将不带www的http/https请求转换为带www的https请求以及将带www的http/https请求转换为不带www的https请求。

338

被折叠的 条评论
为什么被折叠?



