1、openssl 生成证书
openssl req -x509 -nodes -days 36500 -newkey rsa:2048 -keyout nginx.key -out nginx.crt
2、nginx 配置https
server {
listen 443;
server_name localhost;
root html;
index index.html index.htm;
ssl on;
ssl_certificate /etc/nginx/ssl/nginx.crt; # 上述第一步生成的文件,并将其放到/etc/nginx/ssl/目录下,别的目录也可以
ssl_certificate_key /etc/nginx/ssl/nginx.key;#同上所述
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
ssl_prefer_server_ciphers on;
location / {
try_files $uri $uri/ =404;
}
}
3、检查配置
命令行输入nginx -t 如下表示成功
cean@linuxgroupcodeserver:/usr/share/nginx/html$ sudo nginx -t
[sudo] cean 的密码:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
cean@linuxgroupcodeserver:/usr/share/nginx/html$
4、重载配置
sudo nginx -s reload