nginx的https的搭建

实验:

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

2.该网站具备账户验证

3.测试https的搭建

创建虚拟主机的发布目录

root@server \~\]# mkdir -p /web/dsj \[root@server \~\]# echo "Welcome" \> /web/dsj/index.html **创建证书** 创建非对称加密使用的私钥文件(可直接将证书安装到对应服务目录下) \[root@server \~\]# openssl genrsa -out dsj.key 通过私钥文件生成证书文件 \[root@server \~\]# openssl req -new -key dsj.key -x509 -days 365 -out dsj.crt req:申请创建证书(request); -new:新的证书; -key dsj.key:使用dsj.key这个密钥; -509:此为测试证书; -days:证书有效期 ![](https://i-blog.csdnimg.cn/direct/87c6472cd5c14800baf3341fe4bea40f.png) **搭建一个https网站** 将生成生成证书移动到nginx配置目录中 \[root@server \~\]# mv dsj.crt dsj.key /etc/nginx/ 绑定虚拟主机和证书 \[root@server \~\]# vim /etc/nginx/nginx.conf server{ listen 443 ssl; server_name 192.168.131.100; root /web/dsj; ssl_certificate /etc/nginx/dsj.crt; ssl_certificate_key /etc/nginx/dsj.key; } 检查配置文件,然后加载配置文件 \[root@server \~\]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful \[root@server \~\]# nginx -s reload 浏览器验证 ![](https://i-blog.csdnimg.cn/direct/1ad53286bc5d48cb8c1ac970f24eafcd.png) ![](https://i-blog.csdnimg.cn/direct/280f9d12c979446a987cf7f79c4c3c90.png) **搭建账户验证功能的网站** 安装工具:httpd-tools \[root@server \~\]# dnf install nginx httpd-tools -y 使用htpasswd关联dsj和网站 \[root@server \~\]# htpasswd -c /etc/nginx/passswd dsj New password: Re-type new password: Adding password for user dsj 修改nginx的配置文件 \[root@server \~\]# vim /etc/nginx/nginx.conf auth_basic "please input your passwd"; #登录提示 auth_basic_user_file /etc/nginx/passwd; #管理网站和密码文件 检查配置文件,然后加载配置文件 \[root@server \~\]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful \[root@server \~\]# nginx -s reload 浏览器验证 ![](https://i-blog.csdnimg.cn/direct/297abd2ae7034a0ebfc93e5a3b8c2190.png)

相关推荐
掘根17 分钟前
【仿Muduo库项目】HTTP模块3——HttpContext子模块
网络·网络协议·http
瓦尔登湖懒羊羊24 分钟前
到底能不能把HTTP1.0讲明白了
http
小李独爱秋1 小时前
计算机网络经典问题透视:TLS协议工作过程全景解析
运维·服务器·开发语言·网络协议·计算机网络·php
不穿格子的程序员3 小时前
计算机网络篇1:OSI + HTTP进化史 + 三次握手四次挥手
网络协议·计算机网络·http
常温5103 小时前
关于网卡如何给CPU减负方法及策略
网络协议·tcp/ip·udp
莫小墨3 小时前
Modbus协议
网络协议
汤愈韬4 小时前
防火墙双机热备技术之VRRP
网络·网络协议·网络安全·security·huawei
北京耐用通信4 小时前
告别通信干扰与距离限制:耐达讯自动化Profibus总线光纤中继器赋能伺服驱动器稳定连接
人工智能·科技·网络协议·自动化·信息与通信
乾元5 小时前
10 个可复制的企业级项目:从需求到交付的 AI 网络工程模板(深度实战版)
运维·网络·人工智能·网络协议·安全
我是海飞5 小时前
杰理 AC792N WebSocket 客户端例程使用测试教程
c语言·python·单片机·websocket·网络协议·嵌入式·杰理