1.更改conf配置
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /usr/local/nginx/ssl/server.crt;
ssl_certificate_key /usr/local/nginx/ssl/server.key;
location / {
root /home/dist;
index index.html index.htm;
}
location /req/{
proxy_pass_header Server;
proxy_set_header Host $http_host;
client_max_body_size 1000M;proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:5000/req/;
}
}
2.加入SSL需要的文件
在 /usr/local/nginx 目录下创建 ssl 文件夹,把域名的证书文件放到ssl文件夹内
3.重启 Nginx
/usr/local/nginx/sbin/nginx -s reload
报错:
nginx: [emerg] unknown directive "ssl" in /usr/local/nginx/conf/nginx.conf
原因:Nginx 未引入 SSL 模块
4.进入Nginx的解压目录安装SSL模块
一般解压目录:/usr/local/nginx/ 例如:我安装的版本是nginx-1.19.9
cd /usr/local/nginx/nginx-1.19.9/
执行
./configure --with-http_ssl_module
5.执行make
make
6.备份原来的Nginx
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
7.新 Nginx 替换原 Nginx
cp -rfp objs/nginx /usr/local/nginx/sbin/nginx
8.检查Nginx配置
/usr/local/nginx/sbin/nginx -t
9.重启 Nginx
/usr/local/nginx/sbin/nginx -s reload
来源:http://www.manongjc.com/detail/28-xhlmdsdtnykhgbh.html