nginx针对某个url限制ip访问,常用于后台访问限制

需要注意的是,在这个location下也得加入php解析相关的配置,否则php文件无法解析。

 
    location ~ .*admin.* {
        allow 1.1.1.1;
        allow 12.12.12.0/24;
        deny all;
        location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass  unix:/tmp/php-fcgi.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
        }
    }

或者设置密码验证

location ~ .admin.php
                        {
                                #allow 1.1.1.1;
                                #allow 12.12.12.0/24;
                                #deny all;
                auth_basic "Authorized users only";
                auth_basic_user_file /usr/local/nginx/conf/auth/password.conf;
 
                location ~ .*\.(php|php5)?$
                                {
                                try_files $uri =404;
                                #fastcgi_pass  unix:/tmp/php-cgi.sock;
                                fastcgi_pass 127.0.0.1:9000;
                                fastcgi_index index.php;
                                include fastcgi.conf;
                                }
                        }

wordpress 后台密码保护 nginx

location ~ /wp-login\.php  {
location ~ .*\.(php|php5)?$
    {
        fastcgi_pass unix:/tmp/php-cgi.sock;
        fastcgi_index index.php;
        include fcgi.conf;
    }
  auth_basic            "Restricted";
  auth_basic_user_file  htpasswd;
}

还没有评论,快来抢沙发!

发表评论

  • 😉
  • 😐
  • 😡
  • 😈
  • 🙂
  • 😯
  • 🙁
  • 🙄
  • 😛
  • 😳
  • 😮
  • emoji-mrgree
  • 😆
  • 💡
  • 😀
  • 👿
  • 😥
  • 😎
  • ➡
  • 😕
  • ❓
  • ❗
  • 65 queries in 0.407 seconds