2017-04-21 58 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; 
.... 
} 

請確保您使用「=」符號,否則它將無法正常工作。