随着技术的发展,以及浏览器的要求,越来越多的http站点开始转为https。为保证原来用户收藏的http站点能继续使用,需要在访问http时,自动跳转到https。
前端Nginx支持https即可,后端服务可继续使用http。
修改nginx.conf
upstream www.nowfox.com{
server 127.0.0.1:9010;
}
server {
listen 80;
server_name www.nowfox.com;
rewrite ^(.*) https://$server_name$1 permanent;
}
server {
listen 443;
server_name www.nowfox.com;
ssl on;
ssl_certificate /data/cert/www.pem;
ssl_certificate_key /data/cert/www.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://www.nowfox.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/nginx/html;
}
}
然后刷新配置文件
sudo /usr/local/nginx/sbin/nginx -s reload