0

I try to restrict the access to some laravel route path but still without success. Looks like the request is handled by error_page 404 definition because if I comment those line nginx show error 404.

http://admin.domain.com/accounts/login

This is my config

server {
  listen 80;
   server_name admin.domain.com;
    error_page  404 = /index.php;
    if (!-e $request_filename) {
    rewrite ^.*$ /index.php last;
    }
    root /home/backend/admin/public;
    access_log /home/backend/admin/logs/access.log;
    error_log /home/backend/admin/logs/error.log;

    location / {
        index  index.html index.htm index.php;
    }


location ~ /accounts/login {
  auth_basic "Protected Area";
  auth_basic_user_file /etc/nginx/htpasswd;
location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php/php7.0-fpm-admin.sock;
        fastcgi_read_timeout 900s;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php/php7.0-fpm-admin.sock;
        fastcgi_read_timeout 900s;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}

1 Answer 1

0

I found the solution. After I removed

if (!-e $request_filename) { rewrite ^.*$ /index.php last; }

Because this if statement discards everything else.

By this way is fine

server {
  listen 80;
  server_name admin.domain.com;
  error_page  404 = /index.php;
  index index.html index.htm index.php;
  root /home/backend/admin/public;
  access_log /home/backend/admin/logs/access.log;
  error_log /home/backend/admin/logs/error.log;

  location ~ /accounts/login {
  auth_basic "Protected Area";
  auth_basic_user_file /etc/nginx/htpasswd;
   }
  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }
  location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php/php7.0-fpm-admin.sock;
        fastcgi_read_timeout 900s;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

  }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .