公司的域名增加了ssl证书,需要把访问http的流量全部转到https上,nginx 80端口重定向到443端口,也就是http访问自动跳转到https。
一、按照如下格式修改nginx.conf 配置文件,80端口会自动转给443端口,这样就强制使用SSL证书加密了。访问http的时候会自动跳转到https上面。
server {
listen 80;
server_name www.百度.com; #你的域名
rewrite ^(.*)$ https://${server_name}$1 permanent;
}
server {
listen 443 ssl;
server_name 你的域名;
ssl_certificate /PATH/xxxxx.pem;
ssl_certificate_key /PATH/xxxxxx.key;
keepalive_timeout 70;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_session_tickets on;
ssl_stapling on;
ssl_stapling_verify on;
ssl_prefer_server_ciphers on;
location / {
alias /xxx/xxx/xxx/;
index index.html index.htm;
}
location ~ /ht { #访问资源,没有可以省略本段
proxy_pass http://localhost:port;
rewrite "^/ht/(.*)$" /$1 break;
}
}
二、重启nginx。
sudo nginx -t
sudo nginx -s reload