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)

相关推荐
wanhengidc8 小时前
云手机的适配性怎么样?
运维·服务器·安全·智能手机·云计算
jimy18 小时前
安卓里运行Linux
linux·运维·服务器
哟哟耶耶9 小时前
js-fetch流式实现中断重连
运维·服务器
爱凤的小光9 小时前
Linux清理磁盘技巧---个人笔记
linux·运维
字节数据平台11 小时前
刚刚,火山引擎多模态数据湖解决方案发布大数据运维Agent
大数据·运维·火山引擎
原神启动111 小时前
Docker 场景化作业:生产环境容器操作实训
运维·docker·容器
云老大TG:@yunlaoda36012 小时前
如何通过华为云国际站代理商CSBS进行备份策略设置?
运维·数据库·华为云
码里法12 小时前
centos安装nginx并配置https完整版
nginx·https·centos
zly350013 小时前
linux查看正在运行的nginx的当前工作目录(webroot)
linux·运维·nginx
QT 小鲜肉13 小时前
【Linux命令大全】001.文件管理之file命令(实操篇)
linux·运维·前端·网络·chrome·笔记