# Location directive disaster

**URL:** <https://www.ruby-forum.com/t/location-directive-disaster/207450>\
**Category:** NGINX\
**Created:** [May 26, 2011, 12:57am UTC](https://www.ruby-forum.com/t/location-directive-disaster/207450 "2011-05-26T00:57:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [May 26, 2011, 12:57am UTC](https://www.ruby-forum.com/t/location-directive-disaster/207450/1 "2011-05-26T00:57:45Z")

</div>

Hi everyone

I have moved from Apache2 to Nginx. I am finding it difficult working  
out what is going on with the location directive. I’ve looked at various  
tutorials and blogs but I’m still encountering problems.

Basically I have a new website that I’m hosting off a directory of the  
current one. Lets call it /newwebsite. To prevent people getting to it,  
I’ve put http-basic authentication around it:

```
            ## Default Location
            location / {
                    index index.php index.html;
            }

            location /newwebsite {
                    index index.php index.html;
                    auth_basic "Unauthorised use

```

prohibited";  
auth\_basic\_user\_file  
/home/username/www.website.com/.htpasswd;  
}

There’s an admin section as well. I will need http authentication on  
this, even when it goes live, to stop people gaining access to the admin  
function:

```
            location /newwebsite/admin {
                    index login.php;
                    auth_basic "Unauthorised use

```

prohibited";  
auth\_basic\_user\_file  
/home/username/www.website.com/.htpasswd;

```
            }

```

Of course I have the catch-all for all the php scripts:

```
            location ~ \.php$ {
                    include /etc/nginx/fastcgi_params;
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME

```

$document\_root$fastcgi\_script\_name;  
fastcgi\_param PATH\_INFO  
$fastcgi\_script\_name;  
}

So:

When I visit [http://domain.com/newsite/admin](http://domain.com/newsite/admin) I get prompted for a http  
basic-auth username and password - as expected. This works.

When I visit [http://domain.com/newsite/admin/admin.php](http://domain.com/newsite/admin/admin.php) I am straight in  
without http basic-auth. This is not so good…!!

So perhaps I’m doing this all wrong?

Posted at Nginx Forum:

> **[Location directive disaster](https://forum.nginx.org/read.php?2,200935,200935#msg-200935)**
>
> Hi everyone I have moved from Apache2 to Nginx. I am finding it difficult working out what is going on with the location directive. I've looked at various tutorials and blogs but I'm still encountering problems. Basically I have a new website that...

---

<div class="post-metadata">

**Author:** ![phil1886](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@phil1886](https://www.ruby-forum.com/u/phil1886)\
**Post date:** [May 26, 2011, 1:16am UTC](https://www.ruby-forum.com/t/location-directive-disaster/207450/2 "2011-05-26T01:16:27Z")

</div>

On 26 May 2011 00:57, phil1886 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi everyone

Hi.

> When I visit [http://domain.com/newsite/admin/admin.php](http://domain.com/newsite/admin/admin.php) I am straight in  
> without http basic-auth. This is not so good..!!

You have to put a copy of the ~ .php$ location block inside the  
protected  
location block (nested), otherwise the php block takes precedence and  
the  
location parser does not match anything else.

I had exactly the same problem: [http://forum.nginx.org/read.php?2,189220](http://forum.nginx.org/read.php?2,189220)

Thomas

---

<div class="post-metadata">

**Author:** ![phil1886](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@phil1886](https://www.ruby-forum.com/u/phil1886)\
**Post date:** [May 26, 2011, 1:41am UTC](https://www.ruby-forum.com/t/location-directive-disaster/207450/3 "2011-05-26T01:41:58Z")

</div>

Thank you!!

Posted at Nginx Forum:

> **[Re: Location directive disaster](https://forum.nginx.org/read.php?2,200935,200942#msg-200942)**
>
> Hi everyone I have moved from Apache2 to Nginx. I am finding it difficult working out what is going on with the location directive. I've looked at various tutorials and blogs but I'm still encountering problems. Basically I have a new website that...
