安装certbot
yum install epel-release -y
yum install certbot -y
生成证书(域名:app.xxxxxx.com)
certbot certonly --manual --force-renewal --server https://acme-v02.api.letsencrypt.org/directory --preferred-challenges dns-01 -d "app.xxxxxx.com"
nginx安装证书
可能的问题:Nginx如果未开启SSL模块,配置Https时提示错误(the “ssl” parameter requires ngx_http_ssl_module)
原因:nginx缺少http_ssl_module模块,编译安装的时候带上–with-http_ssl_module配置就行了
cd /usr/local/nginx/sbin
./nginx -V
查看nginx信息,如果没有ssl模块,configure arguments:后面是没有的,这个图显示已安装,如果未安装则要重新安装
重新配置
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
配置完成后,运行make命令,但是不要运行make install
备份:cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
停止nginx,然后将刚刚编译好的nginx覆盖掉原有的nginx,这个objs是在解压之后的nginx文件夹里
cp ./objs/nginx /usr/local/nginx/sbin/
再次回到安装位置,使用./nginx -V查看是否已成功安装
nginx配置ssl
第一个server:
server {
listen 80;
server_name localhost;
location / {
#前端文件路径
root /usr/local/projects/xxx/web/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://127.0.0.1:8090;
proxy_set_header Host 127.0.0.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
第二个server
server {
listen 443 ssl;
server_name app.xxx.com; #域名
ssl_certificate /usr/local/environment/ssl/app.xxx.com/fullchain.pem;
ssl_certificate_key /usr/local/environment/ssl/app.xxx.com/privkey.pem;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://app.xxx.com:80;
}
}
之后使用 ./nginx -t 检查配置文件是否有误
./nginx -s reload