美文网首页
nginx的http跳转https配置

nginx的http跳转https配置

作者: 夜清溟 | 来源:发表于2019-12-30 17:02 被阅读0次

在nginx.conf配置文件中添加:

server {
    listen 80;
    server_name *.easex.cn;   
    return 301 https://$http_host$request_uri;
}

在nginx.conf文件或者子配置文件中添加:

server {
    listen 443 ssl http2;
    server_name *.easex.cn;
    
    ssl_certificate     cert/easex.cn/fullchina.cer;
    ssl_certificate_key cert/easex.cn/easex.cn.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSV1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_prefer_server_ciphers on;
    
    access_log logs/easex.cn_access.log;
    error_log  logs/easex.cn_error.log;
                
    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;

        proxy_pass http://tomcat9/;
    }

}

 *.easex.cn为域名,当访问网站时,监听到80端口,那么NGINX会将80端口301重定向到https,也就是443端口监听的服务。
服务器需要打开80和443端口。

相关文章

网友评论

      本文标题:nginx的http跳转https配置

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