Nginx位置允许ip无法按预期工作

问题描述 投票:0回答:2

设置位置允许我需要你的帮助,

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;
}
nginx
2个回答
1
投票

所以你的问题不是允许和拒绝。它是root /usr/share/;因为你把它放在一个位置块location /phpmyadmin,它无法找到location \admin因此,它返回404.尝试将root /usr/share/放置到服务器块而不是位置块。


0
投票

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

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

确保使用“=”符号,否则它将无效。

© www.soinside.com 2019 - 2024. All rights reserved.