Centos7 用Nginx部署https测试页面
安装Nginx和openssl
:
yum install nginx openssl -y
生成SSL证书:
mkdir /etc/nginx/ssl cd /etc/nginx/ssl openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout nginx.key -out nginx.crt -subj "/CN=yourdomain.com/O=yourdomain.com"
配置Nginx以使用SSL:
vim /etc/nginx/nginx.conf
http
块中添加以下内容:
server { listen 443 ssl; server_name yourdomain.com; # 替换为你的域名或IP ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; location / { root /usr/share/nginx/html; index index.html index.htm; } }
启动Nginx服务:
systemctl start nginx
测试你的HTTPS服务器:
curl -k https://yourdomain.com