Reputation: 13
Denying access to a path on Nginx with Laravel works but the visited page breaks on the allowed IP address. What am I doing wrong?
I have been using the following snippet to block access to http://some.url/admin (and http://some.url/admin/login). Works for other purposes, like Wordpress.
# Restrict administrative access
location /admin/ {
allow x.x.x.x;
deny all;
}
I get an 403 error when visiting from a non-allowed IP, which is good. 👍
But I get an 404 error when visiting from the allowed IP. 👎
2017/02/20 18:40:36 [error] 2663#2663: *325 "/var/www/some-website/html/public/admin/index.php" is not found (2: No such file or directory), client: x.x.x.x, server: some.website, request: "GET /admin/ HTTP/2.0", host: "some.website"
I suspect something goes wrong with the routes in my Laravel application.
A lot of trial and error, searching on the web and StackOverflow gave me no successful answers. Thanks in advance!
PS. This is my first post. If I am doing something wrong please tell me.
Upvotes: 1
Views: 1376
Reputation: 8130
It is possible. Point the location back to the root by adding this to the location block:
try_files $uri $uri/ /index.php?$query_string;
Upvotes: 2