zoukankan      html  css  js  c++  java
  • nginx访问权限设置

    nginx的访问控制

    1、前提准备

    安装nginx:

    https://www.cnblogs.com/liuzhijun666/p/13124033.html

    2、根据Ip来限制主机访问

    [root@server ~]# cd /usr/local/nginx/conf/
    [root@server conf]# vim nginx.conf
      server {
            listen       80;	#端口号
            server_name  www.example.com;	#设置访问域名
            location / {
                root   html;				#文件位置默认html
                index  index.html index.htm;
                allow 192.168.7.10/32;  #允许访问的Ip(这是本机Ip),或者网段
               deny all;			#deny禁止,all所有
            }
              
           }
           
           
     #本机ip访问
    [root@server conf]# echo 123 > ../html/index.html 
    [root@server conf]# systemctl restart nginx
    [root@server conf]# curl www.example.com
    123
    [root@server conf]# 
    

    外面效果:

    3、用户认证访问

    [root@server ~]# cd /usr/local/nginx/conf/
    [root@server conf]# vim nginx.conf
    server {
            listen       80;
            server_name  www.example.com;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
                auth_basic "欢迎信息";
                auth_basic_user_file "/usr/local/nginx/conf/passwd";  //账户密码文件
            }
    }
    [root@server conf]# systemctl restart nginx
    [root@server conf]# yum install -y httpd-tools
    [root@server conf]# htpasswd -c -m /usr/local/nginx/conf/passwd user
    New password: 123
    Re-type new password: 123
    Adding password for user user
    [root@server conf]# systemctl restart nginx
    

    效果:

    用户:user

    密码:123

  • 相关阅读:
    C# 委托应用总结
    C语言指针总结
    SQL2005四个排名函数(row_number、rank、dense_rank和ntile)的比较
    C#接口
    C# Linq
    C#反射
    重写与重载
    mysql01
    ajax
    bootstrap02导航菜单
  • 原文地址:https://www.cnblogs.com/liuzhijun666/p/13138177.html
Copyright © 2011-2022 走看看