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

时间:2017-04-21 23:18:10

标签: nginx

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

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;
}

配置文件(在路线上有两个例子):

.[]

2 个答案:

答案 0 :(得分:1)

所以你的问题不是允许和拒绝。它是root /usr/share/;由于您已将其放入位置区location /phpmyadmin,因此location \admin无法找到它。因此,它会返回404.尝试将root /usr/share/放入服务器块而不是位置块。

答案 1 :(得分:0)

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

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

确保使用&#34; =&#34;签字否则它不会工作。