degoya
degoya

Reputation: 1

nginx rewrite & auth_basic (modx cms)

I'd like to protect the root with passwd and make the urlfriendly rewrite for modx cms. only the rewriting works but the password won't be requested.

my ispconfig nginx directives looks like this

location / {
    index index.html index.php
    auth_basic "Protected Area";
    auth_basic_user_file /var/www/clients/client21/web22/web/htpasswd;
    client_max_body_size 0;
    if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php?q=$1 last;
    }
}

location ~ /\.ht {
    deny  all;
}

location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass  unix:/var/run/php5-fpm.sock;
    fastcgi_read_timeout 600; 
    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;
    client_max_body_size 0;
}

seems like the auth_basic won't be executed or overwriten by the rewrite rule. anyone got a idea?

after alot of ppl viewing this question but i didn't received a answer here i post the solution to the problem. The problem was that the basic auth needs to be done in the php directive.

location / {
    index index.html index.php
    client_max_body_size 0;
    if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php?q=$1 last;
    }
}

location ~ /\.ht {
    deny  all;
}

location ~ \.php$ {
    auth_basic "Protected Area";
    auth_basic_user_file /var/www/clients/client21/web22/web/htpasswd;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass  unix:/var/run/php5-fpm.sock;
    fastcgi_read_timeout 600;
    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;
    client_max_body_size 0;
}

Upvotes: 0

Views: 515

Answers (1)

Oriol
Oriol

Reputation: 12730

Try this set of rules. No PHP directives and leverages FURLS.

location / { 
  auth_basic "Restricted"; 
  # Add path to .htpasswd file
  auth_basic_user_file /var/www/clients/client21/web22/web/.htpasswd;
  # if the protected location is modx, then ...
  try_files $uri $uri/ @modx-rewrite;
  # otherwise, if static files, you’d use
  # try_files $uri $uri/ =404;
  # This line should always be placed at the end
  try_files $uri $uri/ @modx-rewrite; 
}

Upvotes: 0

Related Questions