How to allow specific IP's to a URL (not directory!) in Nginx
-
I'm trying to deny access to a specific URL on our site running on Nginx but allow it from specific IP's, I've been trying to fiddle around using Location but it seems that's just trying to find a proper directory and not the URL. This is what I came up with, but just gives back a 404. location /specificurl { root /var/www/site1.com/current; allow 123.123.123.123; deny all; }
-
Answer:
I managed to solve it myself, and this is how: set $deny_access off; if ($remote_addr !~ (123.123.123)) { set $deny_access on; } if ($uri ~ "^/(specificurl)$" ) { set $deny_access on$deny_access; } if ($deny_access = onon) { return 444; }
Lars at Server Fault Visit the source
Other answers
You are trying to return a 404 error for all IP, but the specified? Use the directive "error_page" with "=404" parameter. Sort of ... location /specificurl { root /var/www/site1.com/current; allow 123.123.123.123; deny all; error_page 403 =404 /404.html; } http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page Furthermore, it is possible to change the response code to another, for example: error_page 404 =200 /empty.gif; Or something like ... location /specificurl { root /var/www/site1.com/current; allow 123.123.123.123; deny all; error_page 403 = @goaway; } location @goaway { return 444; }
cadmi
Related Q & A:
- How can I force the login to a specific ip address?Best solution by Stack Overflow
- How to list all text files in a directory?Best solution by Stack Overflow
- How to log in to my website from specific IP address?Best solution by Yahoo! Answers
- How to change column data's as a separate column wise format in a SQL Server?Best solution by stackoverflow.com
- How can hotspots support more people than the number of IP's allowed in a typical IPv4 IP range?Best solution by Server Fault
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.