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网站

将生成生成证书移动到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

浏览器验证

搭建账户验证功能的网站

安装工具: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

浏览器验证

相关推荐
王二端茶倒水1 天前
从千兆到万兆:宽带运营不能只卖套餐,要管用户生命周期从千兆到万兆:宽带运营需要管理用户生命周期
后端·网络协议·架构
牛奶2 天前
HTTPS你不知道的事
前端·https·浏览器
extrao3 天前
🚀 Kea DHCP4 自动分配系统完整搭建
网络协议
喵个咪4 天前
Go-Wind HTTP 服务器从入门到精通
后端·http·go
不做菜鸟的网工5 天前
BGP特性
网络协议
AlfredZhao5 天前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80
明月_清风7 天前
开发者网络概念全扫盲:一篇搞定
后端·网络协议
刘马想放假7 天前
Modbus 全栈技术解析:TCP、RTU、ASCII、RTU over TCP
数据结构·网络协议
王二端茶倒水9 天前
一套可落地的无线运营方案,不能只管 AP,还要管用户、计费和运维
网络协议