美文网首页
nginx配置http重定向https

nginx配置http重定向https

作者: 喜叔z | 来源:发表于2019-08-11 10:40 被阅读0次

事件:部署了一个项目,发现浏览器输入网址,浏览器识别是http的,而我的网站配置了ssl 且只有https的时候才能访问,于是需要重定向 是监听80端口的网站重新定向到https,实现http自动跳转https
解决:重新配置nginx

cd /etc/nginx/conf.d
sudo vim order.conf
server {
    listen 80;
    server_name 网址;
    return 301 https://$server_name$request_uri;
}
server {
    listen 443 ssl;
    server_name 网址;
    ssl on;
        ssl_certificate /data/www/https/chained.pem;
        ssl_certificate_key /data/www/https/domain.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA;
        ssl_session_cache shared:SSL:50m;
        location /static {
                alias /data/www/orderAll/web/static/;
        }
        location /.well-known/acme-challenge/ {
                alias /data/www/challenges/;
                try_files $uri =404;
        }
        location / {
                try_files $uri @yourapplication;
        }
        location @yourapplication {
                include uwsgi_params;
                uwsgi_pass unix:/data/www/logs/order.sock;
        }
}

重新加载nginx

sudo service nginx reload

启发原文https://www.cnblogs.com/nuccch/p/7681592.html

相关文章

网友评论

      本文标题:nginx配置http重定向https

      本文链接:https://www.haomeiwen.com/subject/fspjjctx.html