# Nginx HttpAccessModule command invalid when rewrite command existed

**URL:** <https://www.ruby-forum.com/t/nginx-httpaccessmodule-command-invalid-when-rewrite-command-existed/213709>\
**Category:** NGINX\
**Created:** [November 9, 2011, 3:31pm UTC](https://www.ruby-forum.com/t/nginx-httpaccessmodule-command-invalid-when-rewrite-command-existed/213709 "2011-11-09T15:31:16Z")\
**Posts on this page:** 4\
**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:** [November 9, 2011, 3:31pm UTC](https://www.ruby-forum.com/t/nginx-httpaccessmodule-command-invalid-when-rewrite-command-existed/213709/1 "2011-11-09T15:31:16Z")

</div>

In the following simple case:

location /entry1 {  
allow 127.0.0.1;

}

---

<div class="post-metadata">

**Author:** ![li\_zJay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8baadc/32.png) [@li\_zJay](https://www.ruby-forum.com/u/li_zJay)\
**Post date:** [November 9, 2011, 3:36pm UTC](https://www.ruby-forum.com/t/nginx-httpaccessmodule-command-invalid-when-rewrite-command-existed/213709/2 "2011-11-09T15:36:13Z")

</div>

In the following simple case:

location /entry1 {  
allow 127.0.0.1;  
deny all;  
rewrite \*\*\*;  
}

the allow/deny command has no effect. Is that because rewrite command  
works  
in the earlier phase?

Thanks!

---

<div class="post-metadata">

**Author:** ![li\_zJay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8baadc/32.png) [@li\_zJay](https://www.ruby-forum.com/u/li_zJay)\
**Post date:** [November 9, 2011, 3:43pm UTC](https://www.ruby-forum.com/t/nginx-httpaccessmodule-command-invalid-when-rewrite-command-existed/213709/3 "2011-11-09T15:43:39Z")

</div>

On Wed, Nov 09, 2011 at 10:35:44PM +0800, li zJay wrote:

> In the following simple case:
> 
> location /entry1 {  
> allow 127.0.0.1;  
> deny all;  
> rewrite \*\*\*;  
> }
> 
> the allow/deny command has no effect. Is that because rewrite command works  
> in the earlier phase?

Yes, rewrites run before allow/deny.

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![li\_zJay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8baadc/32.png) [@li\_zJay](https://www.ruby-forum.com/u/li_zJay)\
**Post date:** [November 9, 2011, 3:58pm UTC](https://www.ruby-forum.com/t/nginx-httpaccessmodule-command-invalid-when-rewrite-command-existed/213709/4 "2011-11-09T15:58:29Z")

</div>

Thanks Igor. That is OK, and I had a think and use the following  
commands  
instead:

location /entry1 {  
if ( ! $remote\_addr ~ “^(127.0.0|10.10.10)” ) { return 403; }  
rewrite \*\*\*  
}
