1、 nginx.conf 配置
编辑 /usr/local/nginx/conf/nginx.conf 配置文件:
配置 https server。
注释掉之前的 http server 配置,新增 https server:
server {
listen 443 ssl;
server_name somnus.test.com;
ssl_certificate ../cert/somnus.test.com.pem;
ssl_certificate_key ../cert/somnus.test.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
......
}
2、将 http 重定向 https
server {
listen 80;
server_name somnus.test.com;
#将请求转成https
rewrite ^(.*)$ https://$host$1 permanent;
}
3、重启 nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
如果 80 端口被占用,可以通过kill命令来进行结束进程:
4、 查看端口使用
netstat -lntp
执行看到以下结果就说明我们成功了
[root@iZi5u1azluu464tfbesf3aZ conf]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3322/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2310/sshd
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 3322/nginx: master
2、 结束nginx端口进程
2.1 查看nginx 进程命令
ps aux | grep nginx
2.2 执行结束命令
kill -9 3322
重启 nginx :
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf