Nginx配置Https

  1. 检查是否按照https模块:

    ./nginx -V
    

    --with-http_stub_status_module --with-http_ssl_modul

    如果确实模块回报这个错误:

    nginx: [emerg] the “ssl” parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:

如果没有在解压后的nginx目录下执行:

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
  1. 进入到conf目录创建ssl文件夹存放证书:

    mkdir ssl
    
  2. 设置配置文件:

    server {
        listen 443 ssl;
        server_name wx.aaa.com;
    
        access_log  /var/log/nginx/wx.aaa.https.access.log;#日志位置,可不配置
    
        # ssl on; # 1.15后版本配置这个会报错
        ssl_certificate      ssl/wx.aaa.com.pem;
        ssl_certificate_key  ssl/wx.aaa.com.key;
    
     location  / {
         try_files $uri $uri/ /index.html;
         root /opt/app_static/wechat;#静态资源位置
     }
    
     location /wechat {
         client_max_body_size 5m;
         proxy_pass http://127.0.0.1:10033/wechat;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
     }
      
     }
    
    
    server {
     listen 80;
     server_name wx.aaa.com; 
    
     location  / {
         try_files $uri $uri/ /index.html;
         root /opt/app_static/wechat;
     }                   
     location /wechat {
         client_max_body_size 5m;
         proxy_pass http://127.0.0.1:10033/wechat;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
     }
    }
    

你可能感兴趣的:(Nginx配置Https)