nginx访问控制,用户认证,配置https,zabbix监控nginx状态页面

nginx访问控制,用户认证,配置https,zabbix监控nginx状态页面

nginx访问控制

用于location段
allow:设定允许哪台或哪些主机访问,多个参数间用空格隔开
deny: 设定禁止哪台或哪些主机访问,多个参数间用空格隔开

//测试
[root@nginx ~]# cd /usr/local/nginx/html/
[root@nginx html]# ls
50x.html  index.html
[root@nginx html]# echo 'hello world' > index.html 
[root@nginx html]# systemctl restart nginx

//虚拟机访问
[root@nginx html]# curl 192.168.111.141
hello world

访问测试

image

//修改配置文件
[root@nginx html]# cd ..
[root@nginx nginx]# vim conf/nginx.conf
        location / {
   
            allow 192.168.111.141;		//只允许虚拟机访问
            deny all;
            root   html;
            index  index.html index.htm;
        }
[root@nginx nginx]# systemctl restart nginx

//虚拟机访问
[root@nginx nginx]# curl 192.168.111.141
hello world

访问测试

image

nginx用户认证

//安装httpd工具包
[root@nginx ~]# yum -y install httpd-tools

//修改配置文件
[root@nginx ~]# cd /usr/local/nginx/conf/
[root@nginx conf]# vim nginx.conf
        location / {
   
            root   html;
            index  index.html index.htm;
        }

        location /abc {
    
             auth_basic "ABC"; 
             auth_basic_user_file "/usr/local/nginx/conf/.pass"; 	//密码位置 
             root html;
             index index.html;
        }

//生成用户密码
[root@nginx conf]# htpasswd -cm /usr/local/nginx/conf/.pass runtime
New password: 
Re-type new password: 
Adding password for user runtime
[root@nginx conf]# cat .pass 
runtime:$apr1$nPzAshNM$nvmalzBcNQlagDB3ipABc1		//加密后的密码
[root@nginx conf]# systemctl restart nginx

直接访问

image

访问根下的abc

image

image

nginx配置https

证书申请及签署步骤

a) 生成申请请求 b) RA核验c) CA签署 d) 获取证书

//生成证书
[root@nginx ~]# cd /etc/pki/
[root@nginx pki]# mkdir CA
[root@nginx pki]# cd CA/
[root@nginx CA]# mkdir private
[root@nginx CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048)		//括号必须要
Generating RSA private key, 2048 bit long modulus (2 primes)
........+++++
............................................................................+++++
e is 65537 (0x010001)
[root@nginx CA]# ls private/
cakey.pem

//CA生成自签署证书
[
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Zabbix是一个开源的网络监控工具,可以用来监控各种网络设备和服务的状态。在监控nginx运行状态方面,可以通过自定义key或使用监控模板来实现。 方法一:自定义key实现监控nginx运行状态 1. 在zabbix-agent端操作,可以使用命令"zabbix_get -s <zabbix-agent IP> -k 'nginx.status'"来获取nginx的运行状态。当nginx运行时,会显示"running",不运行时,会显示"dead"。\[1\] 2. 在zabbix-agent端操作,将监控脚本与zabbix-agent关联起来,确保监控脚本能够正确获取nginx的运行状态。\[2\] 3. 在web端创建监控项和触发器,监控项使用自定义key来获取nginx的运行状态,触发器根据需要设置相应的条件和动作。 方法二:使用监控模板监控nginx运行状态 1. 创建监控项,使用预定义的监控模板中的项来监控nginx的运行状态。 2. 创建触发器,根据监控项的数值设置相应的条件和动作。 3. 验证监控是否生效,可以使用命令"zabbix_get -s <zabbix-server IP> -k 'nginx.status\[accepts\]'"来测试监控是否正常工作。\[2\] 通过以上两种方法,可以实现对nginx运行状态监控,并根据需要设置相应的触发器来进行告警或其他操作。 #### 引用[.reference_title] - *1* *3* [zabbix监控系统——zabbix实现对nginx运行状态监控](https://blog.csdn.net/weixin_44178770/article/details/124706744)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [zabbix监控nginx](https://blog.csdn.net/qq_37369726/article/details/103383468)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值