nginx之https以及nginx状况监控

基于用户的访问

安装包
[root@localhost ~]# yum provides *bin/htpasswd
已加载插件:fastestmirror
Repository 'base': Error parsing config: Error parsing "baseurl = 'local'": URL must be http, ftp, file or https not ""
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
httpd-tools-2.4.6-93.el7.centos.x86_64 : Tools for use with the Apache HTTP Server
源    :base
匹配来源:
文件名    :/usr/bin/htpasswd
[root@localhost ~]# yum -y install httpd-tools
[root@localhost ~]# which htpasswd
/usr/bin/htpasswd
[root@localhost ~]# htpasswd -c -m /usr/local/nginx/conf/.passwd admin
New password: 
Re-type new password: 
Adding password for user admin
[root@localhost ~]# ls /usr/local/nginx/conf/ -a
.                     fastcgi_params.default  nginx.conf           uwsgi_params
..                    koi-utf                 nginx.conf.default   uwsgi_params.default
fastcgi.conf          koi-win                 .passwd              win-utf
fastcgi.conf.default  mime.types              scgi_params
fastcgi_params        mime.types.default      scgi_params.default
[root@localhost ~]# cat /usr/local/nginx/conf/.passwd                 即加密后的密码
admin:$apr1$Ky/Dnmpe$DVuYt3vuP/BNdUt3/OP8R/
配置页面
[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# ls
50x.html  index.html  zabbix
[root@localhost html]# mkdir abc
[root@localhost html]# echo 'abc test page' > abc/index.html
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
[root@localhost ~]# nginx -s reload
#access_log  logs/host.access.log  main;

         location / {
            root   html;
            index  index.html index.htm;
        }
        location /abc {                           //配置abc页面
            root html;
            index index.html;
        }

在这里插入图片描述

配置密码
[root@localhost ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# nginx -s reload
        #access_log  logs/host.access.log  main;

         location / {
            root   html;
            index  index.html index.htm;
        }
        location /abc {
            auth_basic "jjyy";
            auth_basic_user_file /usr/local/nginx/conf/.passwd;   添加密码位置
            root html;
            index index.html;
        }

页面测试
在这里插入图片描述
在这里插入图片描述
配置HTTPS

下载证书需要的包
[root@localhost ~]# yum -y install mod_ssl
[root@localhost ~]# vim /etc/httpd/conf.modules.d/00-base.conf
添加以下内容
LoadModule ssl_module modules/mod_ssl.so

[root@localhost ~]# openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
.............................................+++
.................................+++
e is 65537 (0x10001)

[root@localhost ~]# openssl req -new -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值