nginx的https的搭建

1.防火墙不能关闭,让其开放http协议https协议

2.该网站具备账户验证

3.https

安装nginx

root@localhost ndbzzz\]# yum install nginx -y ![](https://i-blog.csdnimg.cn/direct/36cb84f0325d4baeae7f4e5c7b900823.png) 通过命令systemctl status firewalld.service查看当前防火墙的状态 ![](https://i-blog.csdnimg.cn/direct/fc4c909f29c14a6080cc69861eb95dcb.png) 启动nginx和防火墙 \[root@localhost ndbzzz\]# systemctl start nginx \[root@localhost ndbzzz\]# systemctl enable nginx \[root@localhost ndbzzz\]# systemctl start firewalld \[root@localhost ndbzzz\]# systemctl enable firewalld **开放http80的端口和https443的端口** 命令: #开放80端口(HTTP) firewall-cmd --add-port=80/tcp --permanent ![](https://i-blog.csdnimg.cn/direct/0174fcc3391c4981bb3a18b2e022c758.png) #开放443端口(HTTPS) firewall-cmd --add-port=443/tcp --permanent ![](https://i-blog.csdnimg.cn/direct/5c3a0af814f44efb935a0ad095aa550a.png) firewall-cmd --reload 搭建网站(Https+账户验证) 创建非对称加密使用的私钥文件。 openssl genrsa -out ZYQ.key 通过私钥文件生成证书文件。 openssl req -new -key zyq.key -x509 -days 365 -outhhy.crt #req:申请创建证书 # -new:新的证书 # -key hhy.key:使用hhy.key这个密钥 # -x509: 此为测试证书 # -days: 证书有效期 将上文生成证书移动到nginx配置目录中: ![](https://i-blog.csdnimg.cn/direct/b87b3fc52ae7465599b8c2f875437e73.png) server { listen 80; server_name 你的IP或域名; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name 你的IP或域名; # 自签名SSL证书路径 ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; # 账户验证配置 auth_basic "请输入账户密码"; auth_basic_user_file /etc/nginx/auth/.htpasswd; root /usr/share/nginx/html; index index.html; ![](https://i-blog.csdnimg.cn/direct/f47b21dba27e49eeb6c36cdf01c831ed.png) 1. 1.新增一个管理网站登录的用户(用于用户验证) 2. \[root@server \~\]# useradd admin 3. \[root@server \~\]# passwd admin 新增用户admin专门管理网站登录 1. 将网站和这个账户关联起来 2. 1必须先下载httpd-tools ![](https://i-blog.csdnimg.cn/direct/a4073d32bbdb4960bc53d4e423bed32e.png) 使用htpasswd 关联用户ndbzzz和网站 ![](https://i-blog.csdnimg.cn/direct/ae8307acd10345ee8d7c82c176e6ab7e.png) 检查语法并热更新 ![](https://i-blog.csdnimg.cn/direct/56b4c26f649e4c22aad670ba807c1636.png) ![](https://i-blog.csdnimg.cn/direct/1ab93a8aec0b4b0da16e4e9b3c40b57e.png) ![](https://i-blog.csdnimg.cn/direct/b08187f9a3f544978cdd69048a10c29a.png)

相关推荐
江畔何人初3 分钟前
/etc/profile,.profile,.bashrc三者区分
linux·运维·云原生
会飞的土拨鼠呀13 分钟前
Ubuntu系统缺少 iptables 工具
linux·运维·ubuntu
前端玖耀里13 分钟前
详细介绍Linux命令dig和nslookup
linux·运维·服务器
星期五不见面21 分钟前
jetson naon super使用 sudo /opt/nvidia/jetson-io/jetson-io.py 界面闪退
linux·运维·服务器
FreeBuf_33 分钟前
AutoPentestX:面向 Linux 系统的自动化渗透测试工具包
linux·运维·自动化
Fᴏʀ ʏ꯭ᴏ꯭ᴜ꯭.36 分钟前
Nginx 平滑升级与回滚超详细指南
运维·nginx
坐怀不乱杯魂40 分钟前
Linux网络 - HTTPS
服务器·网络·网络协议·http·https
网硕互联的小客服43 分钟前
linux服务器忘记远程端口怎么办?如何找回?
linux·运维·服务器
历程里程碑44 分钟前
Linux 16 环境变量
linux·运维·服务器·开发语言·数据库·c++·笔记
ZeroNews内网穿透44 分钟前
关于飞牛fnOS重要安全更新的提醒
运维·服务器·web安全·ssh