目录
1.nginx的ssl模块安装
1.1.检查是否安装过ssl模块
1.1.1.进入nginx安装目录的sbin
执行命令,注意是-大写V
./nginx -V
出现configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module表示安装过
1.1.2.下面说没安装过ssl模块的
首先进入nginx的减压目录,我这里是在/root/nginx-1.24.0
然后执行命令,注意–prefix是nginx的安装目录
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
再执行make命令,注意不是make install
make
在objs找到nginx文件,替换下之前安装目录sbin下的nginx
替换之前停止掉nginx
./nginx -s stop
替换命令,替换玩再启动nginx
cp /root/nginx-1.24.0/objs/nginx /usr/local/nginx/sbin
1.2.开启443端口
1.2.1.开启服务器443端口
执行命令开启命令
iptables -I INPUT -p tcp --dport 443 -j ACCEPT
执行保存开启防火墙保存命令
service iptables save
执行重启防火墙命令
service iptables restart
1.2.2.开启服务器安全组443端口
2.配置nginx的配置文件
2.1服务器设置证书pem和key
下载证书
在/etc/下创建ssl文件夹
mkdir ssl
将下载好的证书pem和key文件上传至ssl文件夹下
2.2进入nginx安装目录替换nginx.conf文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# http server
server {
listen 80;
# 域名名称
server_name xxx.com;
charset utf-8;
# 设置跳转至https地址
rewrite ^(.*)$ https://www.xxx.com;
}
# HTTPS server
server {
listen 443 ssl;
server_name xxx.com;
ssl_certificate /etc/ssl/xxx.pem;
ssl_certificate_key /etc/ssl/xxx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /home/apply/web/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/{
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
最后记得重启nginx