centos7.9安装nginx设置https证书访问模式
cd /usr/local
yum install -y wget vim
wget https://nginx.org/download/nginx-1.27.4.tar.gz
tar -zxvf nginx-1.27.4.tar.gz
cd /usr/local/nginx-1.27.4
yum install -y gcc-c++
yum install -y pcre pcre-devel
yum install -y openssl openssl-devel
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make
make install
cd /usr/local/nginx/conf
#上传xxx.key和xxx.pem证书到/usr/local/nginx/conf
vim nginx.conf
#以下为配置前内容截图
#以下为配置后内容截图
################################以下为改好后的conf部分配置
server {
listen 443 ssl; #端口号
server_name localhost; #域名
ssl_certificate /usr/local/nginx/conf/xxx.pem; #公钥证书
ssl_certificate_key /usr/local/nginx/conf/xxx.key; #私钥证书
ssl_protocols TLSv1.2; #协议
ssl_session_timeout 5m; #客户端会话缓存时间
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;
#加密套件
error_log /usr/local/nginx/conf/error.log;
#错误日志
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
################################
systemctl status firewalld
firewall-cmd --zone=public --add-port=443/tcp --permanent
systemctl restart firewalld
systemctl enable firewalld
如果需要查询是否支持SSL模块可以输入nginx -V来查看
例如下面:
/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.27.4
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· 单线程的Redis速度为什么快?
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码