2017-04-21 32 views
0

我需要设置的位置让你的帮助没有工作的ip,Nginx的位置让预期

location /route { 
    deny [my-ip]; 
} 

所以这个作品,它不会让我访问路线

抛出这个错误

403 Forbidden 
nginx/1.10.0 (Ubuntu) 

这...

location /route { 
    allow [my-ip]; 
    deny all; 
} 

不会让我的访问,但它应该让我访问路线,不明白为什么,它表明这个错误

404 Not Found 
nginx/1.10.0 (Ubuntu) 

配置文件(航线上两个例子):

# Add index.php to the list if you are using PHP 
index index.php index.html index.htm; 

server_name [my-domain]; 

location/{ 
    # First attempt to serve request as file, then 
    # as directory, then fall back to displaying a 404. 
    try_files $uri $uri/ /index.php?$query_string; 
} 

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
# 
location ~ \.php$ { 
    include snippets/fastcgi-php.conf; 
# 
# # With php7.0-cgi alone: 
# fastcgi_pass 127.0.0.1:9000; 
# # With php7.0-fpm: 
    fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
} 

# deny access to .htaccess files, if Apache's document root 
# concurs with nginx's one 
# 
location ~ /\.ht { 
    deny all; 
} 

# Phpmyadmin Configurations 
location /phpmyadmin { 
    root /usr/share/; 
    index index.php index.html index.htm; 
    location ~ ^/phpmyadmin/(.+\.php)$ { 
      try_files $uri =404; 
      root /usr/share/; 
      #fastcgi_pass 127.0.0.1:9000; 
      #fastcgi_param HTTPS on; # <-- add this line 
      fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include fastcgi_params; 
    } 
    location ~* ^/phpmyadmin/(.+\. 
(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { 
      root /usr/share/; 
    } 
} 

# Dealing with the uppercased letters 
location /phpMyAdmin { 
    rewrite ^/* /phpmyadmin last; 
} 

location /logs { 
    deny [myip]; 
} 

location /admin { 
    allow [myip]; 
    deny all; 
} 
+0

什么叫“不允许你访问路线”呢? –

+0

它显示了这404未找到 的nginx/1.10.0(Ubuntu的) – Janva

+0

您可以共享一个更详细的conf文件? –

回答

1

所以你的问题不是允许和否认。这是root /usr/share/;既然你已经把它变成一个位置块location /phpmyadmin,它不能被发现location \admin因此,返回404尝试将root /usr/share/放置到服务器,而不是块的位置块。

0

给其他人谁正在寻找解决方案。这对我来说,经过长时间的尝试和错误:

location = /phpmyadmin/index.php { 
allow 1.2.3.4; 
deny all; 
.... 
} 

请确保您使用“=”符号,否则它将无法正常工作。