1.将所有HTTP80访问跳转到HTTPS443访问,此方法所有访问此域名80端口的访问都将跳转到443
#301跳转 将80请求全部转发到https
server {
listen 80;
server_name zhtube.com www.zhtube.com;location / {
rewrite (.*) https://www.zhtube.com$1 permanent;
}
}server {
listen 443 ssl;
server_name zhtube.com www.zhtube.com;root /home/vhost/www.zhtube.com;
ssl on;
#这是你的证书目录
ssl_certificate /usr/loacl/nginx/ssl-crt/zhtube.com.crt;
#这是你的证书key目录
ssl_certificate_key /usr/loacl/nginx/ssl-crt/zhtube.com.key;location / {
index index.php;
}}
2.HTTP80和HTTPS443同时访问
server {
listen 80;
listen 443 ssl;
server_name www.zhtube.com;ssl_certificate /usr/loacl/nginx/ssl-crt/zhtube.com.crt;
ssl_certificate_key /usr/loacl/nginx/ssl-crt/zhtube.com.key;root /home/vhost/www.zhtube.com;
}