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

posted @ 2025-02-12 17:23  昵称昵称昵称  阅读(119)  评论(0)    收藏  举报