【问题标题】:NGINX restriction I.P not workingNGINX 限制 I.P 不起作用
【发布时间】:2017-03-08 16:24:14
【问题描述】:

我的配置有问题,我用的是nginx/1.10.3,php5-fpm。

这是我的默认配置位置:

location / {
  try_files $uri $uri/ =404;
  allow 1.2.3.4; #my ip
  allow 127.0.0.1;
  allow 11.22.33.44; #server ip
  deny all;
}

当我尝试访问 11.22.33.44 时,我有一个 403 Forbidden:

2017/03/08 16:30:25 [error] 340#340: *3 access forbidden by rule, client: 1.2.3.4, server: _, request: "GET / HTTP/1.1", host: "11.22.33.44"

感谢您的帮助!

解决,解决:

location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        allow 127.0.0.1;
        allow 1.2.3.4; #my ip
        deny all;
}

【问题讨论】:

  • 你希望它做什么?
  • @RichardSmith 感谢您的回复,我只想在示例中从我的家庭 IP(1.2.3.4)访问位置/!这是为了测试我的应用程序。 (如果您有另一个想法来测试我的网站而没有任何人可以访问它?我接受)!否则我添加一个 robots.txt 到没有索引的网站
  • 但是应该返回的 URI / 是什么?例如。 index.phpindex.html?
  • @RichardSmith index.php(我使用 codeiginiter,在 localhost 的 apache 上使用 RewriteEngine。
  • 好的,因此/index.php 的访问权限将不受此位置块的控制(无论如何也不完全)。

标签: nginx rules ip-restrictions


【解决方案1】:

检查你的.conf文件,确保自动索引是打开的,否则会出现这个错误

 autoindex on;

【讨论】:

    猜你喜欢
    • 2013-12-14
    • 2018-05-04
    • 2011-02-10
    • 2014-06-15
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    • 2015-04-09
    • 2011-12-23
    相关资源
    最近更新 更多