0
点赞
收藏
分享

微信扫一扫

nginx 1.18 默认网站 访问控制配置

nginx 1.18 默认网站 访问控制配置

一、默认网站

主配置文件中一个server 项目就是默认的网站

server {

       listen       80;

       server_name  localhost;

       #charset koi8-r;

       #access_log  logs/host.access.log  main;

       location / {

#下面也可以写完整的路径/usr/local/nginx/html

           root   html;

           index  index.html index.htm;

       }

       error_page  404              /404.html;

#这里定义了一个404的页面 去建立一个 /usr/local/nginx/logs/

       location = /404.html {

           root   html;

       }

       # redirect server error pages to the static page /50x.html

       #

       error_page   500 502 503 504  /50x.html;

       location = /50x.html {

           root   html;

       }

二、nginx 访问控制

上面的配置不变

主配置文件 再定义一个 location 在上面的error_page  404 上一行开始添加

下面表示以列表的形式显示A这个目录的文件 (去html/a下面建立几个文件)允许10.10.154.0这个网段的

拒绝其他所有的  给不能访问的用户 返回一个404错误页面 也可以返回一个站点www.jd.com

示例1

       location /a {

       autoindex on;

           allow 10.10.154.0/24  ;

          deny all  ;

       if ( $remote_addr !~ "10.10.154" ) {

       return  404;

      #return  http://www.jd.com;

       }

       }


示例2

允许所有 禁止某一IP(受到攻--击时候使用)


 location /a {

       autoindex on;

           deny 10.10.154.25/32  ;

          allow  all  ;

       if ( $remote_addr ~ "10.10.154.25" ) {

       #return  404;

       return http://www.jd.com;

       }

}        






举报

相关推荐

0 条评论