nginx的https的搭建

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

2.该网站具备账户验证

3.https

[root@localhost ~]# vi /etc/yum.repos.d/rhel9-local.repo 修改本地配置文件

导入镜像的GPG密钥 并清理缓存

[root@localhost ~]# rpm --import /media/cdrom/RPM-GPG-KEY-redhat-release
[root@localhost ~]# yum clean all && yum makecache

安装Nginx

[root@localhost ~]# yum install nginx -y

启动nginx和防火墙
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
[root@localhost ~]# systemctl start firewalld
[root@localhost ~]# systemctl enable firewalld

开放http80的端口和https443的端口

[root@localhost ~]# firewall-cmd --add-port=80/tcp --permanent 
[root@localhost ~]# firewall-cmd --add-port=443/tcp --permanent 
[root@localhost ~]# firewall-cmd --reload

自成签名证书

mkdir -p /etc/nginx/ssl
[root@localhost ~]# openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
  -keyout /etc/nginx/ssl/nginx.key \
  -out /etc/nginx/ssl/nginx.crt

修改配置文件nginx

[root@localhost ~]# vim /etc/nginx/conf.d/https.conf
   

配置文件

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;
}
 

生成密码文件

[root@localhost ~]#yum install http
[root@localhost ~]# mkdir -p /etc/nginx/auth
[root@localhost ~]# htpasswd -c /etc/nginx/auth/.htpasswd admin

重新启动nginx

[root@localhost ~]# systemctl restart nginx

查看和修改权限

[root@localhost ~]# ls -l /etc/nginx/auth/.htpasswd 查看

[root@localhost ~]# chown -R nginx:nginx /usr/share/nginx/html
[root@localhost ~]# chmod -R 755 /usr/share/nginx/html

验证:浏览器输入https:// 自己的IP地址 我的(192.168.117.129)

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值