Basic auth not working with rewrite
October 11, 2016 11:20PM
I need to protect one directory with the basic auth and rewrite all urls inside this directory only.

I have the following config:

location /admin/ {
auth_basic "Secure area";
auth_basic_user_file .htpasswd;
rewrite ^(.*)$ /admin/index.php last;
}

However, basic auth not working. If I comment rewrite rule it starts working.

How to fix it?
Re: Basic auth not working with rewrite
October 12, 2016 02:44AM
Try 'break'.

http://stackoverflow.com/questions/28623938/what-is-the-difference-between-break-and-last-in-nginx-rewrite

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Basic auth not working with rewrite
October 12, 2016 09:16AM
itpp2012 Wrote:
-------------------------------------------------------
> Try 'break'.
>
> http://stackoverflow.com/questions/28623938/what-is-the-difference-bet
> ween-break-and-last-in-nginx-rewrite


Thanks. It started working but when I try to reload the page, a file-save dialog appears. What could be the reason of the problem?
Re: Basic auth not working with rewrite
October 12, 2016 01:28PM
Sounds like a PHP issue, it should be passed to a php handler but is seen as downloadable.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Basic auth not working with rewrite
October 14, 2016 05:51AM
PHP is working fine when I use 'last'.

Php config section looks as follows:

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

Please advise.
Re: Basic auth not working with rewrite
October 14, 2016 12:24PM
Look at the logfiles to see the path and php filename which is passed on, might be the path has changed without php.ini having an entry for that path.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Basic auth not working with rewrite
October 17, 2016 03:40AM
itpp2012 Wrote:
-------------------------------------------------------
> Look at the logfiles to see the path and php filename which is passed
> on, might be the path has changed without php.ini having an entry for
> that path.

It seems that php section is not even accessed when the 'break' rule is present.
This is my php-fpm access log section config:

access.log = /var/log/php5-fpm.access.log
access.format = "%t %R %f \"%m %r%Q%q\" %s %{mili}dms %{kilo}Mkb %C%%"
catch_workers_output = yes

It collects requests when 'last' is present, but does not show anything when 'break' is in action.
I googled and it seems that using break is the reason of the problem as it breaks the locaiton lookup.
I think there should be a different soution, Any suggestions?



Edited 1 time(s). Last edit at 10/17/2016 03:46AM by se336.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 148
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready