Custom 401 page not displaying or not prompting for credentials

Michael draxter65 at gmail.com
Sun Jul 14 22:33:15 UTC 2013


Added auth_basic off; as so:

location = /401.html {
                auth_basic off;
                root G:/Files;
            }

returns error 403 and 'access forbidden by rule' error. So then I added
allow all; like this:

location = /401.html {
                allow all;
                auth_basic off;
                root G:/Files;
            }

This takes the user straight to the custom error 401 page without
authentication.


The full config is:

worker_processes 1;

events {
    worker_connections 1024;
}

http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;

    server {
        satisfy any;
        allow 192.168.0.0/24;
        deny all;
        auth_basic "Please login";
        auth_basic_user_file C:\password.txt;
        listen 80;
        server_name localhost;
        root G:/Files;

        location / {
            index  index.html  index.php /_h5ai/server/php/index.php;
            error_page 401 /401.html;
            location = /401.html {
                allow all;
                auth_basic off;
                root G:/Files;
            }
        }
        location ~ \.php$ {
            include fastcgi.conf;
            fastcgi_pass 127.0.0.1:9000;
        }
    }
}


On 14 July 2013 19:54, Maxim Dounin <mdounin at mdounin.ru> wrote:

> Hello!
>
> On Sat, Jul 13, 2013 at 02:40:14PM +0100, Michael wrote:
>
> > Hello, I was trying to set a custom error 401 page on my Nginx server
> > version 1.5.1 using the following methods:
> >
> > error_page 401 /401.html
> > By itself it still displays the default site
> >
> > error_page 401 http://example.com/401.html
> > Goes straight to the custom error page without a chance to authenticate
> >
> > error_page 401 /401.html;
> > location = /401.html
> >         {
> >            root   G:/Files;
> >            allow all;
> > Also goes straight to the error page.
> >
> >
> >
> > My entire config file:
> >
> > worker_processes 1;
> >
> > events
> > {
> >     worker_connections 1024;
> > }
> >
> > http
> > {
> >     include mime.types;
> >     default_type application/octet-stream;
> >     sendfile on;
> >
> >     server
> >     {
> >         satisfy any;
> >         allow 192.168.0.0/24;
> >         deny all;
> >         auth_basic "Please login";
> >         auth_basic_user_file C:\password.txt;
> >         listen 80;
> >         server_name localhost;
> >         root G:/Files;
> >
> >         location /
> >         {
> >             index  index.html  index.php /_h5ai/server/php/index.php;
> >   error_page 401 /401.html;
> >             location = /401.html
> >   {
> >   root G:/Files;
> >   }
> >         }
> >         location ~ \.php$
> >         {
> >             include fastcgi.conf;
> >             fastcgi_pass 127.0.0.1:9000;
> >         }
> >     }
> > }
> >
> >
> > If anyone has any idea what I'm doing wrong, let me know.
>
> Access to /401.html requires authentication, which prevents the
> error page configured from being returned.  Try adding
>
>     auth_basic off;
>
> into location /401.html.
>
> --
> Maxim Dounin
> http://nginx.org/en/donation.html
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20130714/b67fc18e/attachment-0001.html>


More information about the nginx mailing list