nginx配置支持https

1、生成证书
1.1、cd /usr/local/nginx/conf
1.2、生成key(生成一个1024或2048位的密钥)
openssl genrsa -des3 -out zngcloudcms_api.key 1024/2048


1.3、创建签名请求证书
openssl req -new -key zngcloudcms_api.key -out zngcloudcms_api.csr


1.4、签发证书
openssl x509 -req -days 365 -in zngcloudcms_api.csr -signkey zngcloudcms_api.key -out zngcloudcms_api.crt


2、配置nginx
2.1、增加反向代理
upstream backend_api_https{
server 10.23.3.215:8082;
    }
2.2、配置server
server {
        listen       443;
        server_name  10.23.3.215;
ssl on;
ssl_certificate /usr/local/nginx/conf/zngcloudcms_api.crt;
ssl_certificate_key /usr/local/nginx/conf/zngcloudcms_api.key;
        location / {
   #设置主机头和客户端真实地址,以便服务器获取客户端真实IP
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #禁用缓存
   proxy_buffering off;
   root   html;
            index  index.html index.htm;
   #反向代理
   proxy_pass http://backend_api_https;
        }
    }
2.3、重启nginx
kill -9 pid
./nginx
3、问题解决
3.1、unknown directive "ssl"
重新编译nginx
./configure --with-http_ssl_module
make
make install

你可能感兴趣的:(ngnix)