如何使用nginx配置SSL证书?

思路分析: 

监听80端口请求强制跳转到443端口处理。

配置实现

  server {
        listen 443 ssl;
        ssl on;
        server_name  二级域名;#例如:www.baidu.com
        #charset koi8-r;
        ssl_certificate /usr/local/nginx-1.8.1/cert/SSL证书.pem;
        ssl_certificate_key /usr/local/nginx-1.8.1/cert/SSL证书.key;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        charset   utf-8;
        location / {
            proxy_pass   http://127.0.0.1:8080;#反向代理到后端服务器
            index  index.html index.htm;
        }
 
       }
       
    server {
        listen       80;
        server_name  二级域名;#例如:www.baidu.com
        #charset koi8-r;
        #access_log  logs/host.access.log  main;  
        rewrite ^(.*) https://$server_name$1 permanent;#80端口请求都强制跳转到443端口进行处理
        charset   utf-8;
        location / {        
            index  index.html index.htm;
        }
 
       }

 

 
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页