# Rewrite help when files do NOT have a ".php" extension

**URL:** <https://www.ruby-forum.com/t/rewrite-help-when-files-do-not-have-a-php-extension/207727>\
**Category:** NGINX\
**Created:** [June 1, 2011, 2:01pm UTC](https://www.ruby-forum.com/t/rewrite-help-when-files-do-not-have-a-php-extension/207727 "2011-06-01T14:01:25Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![pk899](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pk899](https://www.ruby-forum.com/u/pk899)\
**Post date:** [June 3, 2011, 10:34am UTC](https://www.ruby-forum.com/t/rewrite-help-when-files-do-not-have-a-php-extension/207727/21 "2011-06-03T10:34:41Z")

</div>

As far as why goes, I find this blog post pretty good :  
[http://www.ichilton.co.uk/blog/web/nginx-and-why-you-should-be-running-it-instead-of-or-at-least-in-front-of-apache-380.html](http://www.ichilton.co.uk/blog/web/nginx-and-why-you-should-be-running-it-instead-of-or-at-least-in-front-of-apache-380.html)

But I would not call that a description of the architecture in deep.  
I don’t think there is such a thing, but the closest things I can think  
of are:

- [Nginx Internals](http://www.slideshare.net/joshzhu/nginx-internals)
- [Emiller’s Guide to Nginx Module Development – Evan Miller](http://www.evanmiller.org/nginx-modules-guide.html)
- [Разработка модулей для nginx](http://www.grid.net.ru/nginx/nginx-modules.html) (ru version) or  
[Development of modules for nginx](http://antoine.bonavita.free.fr/nginx_mod_dev_en.html) (my english  
version).

Happy digging,

A.

–  
In for a ride in nginx-land ? Visit: [http://www.nginx-discovery.com](http://www.nginx-discovery.com)

---

<div class="post-metadata">

**Author:** ![pk899](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pk899](https://www.ruby-forum.com/u/pk899)\
**Post date:** [June 3, 2011, 4:09am UTC](https://www.ruby-forum.com/t/rewrite-help-when-files-do-not-have-a-php-extension/207727/22 "2011-06-03T04:09:31Z")

</div>

Sorry I was not clear.

Yes I reran the ./configure --with-debug among other things, and then  
make and make install.

Yes I only want to debug connections from that one IP, my IP. But even  
that is not working.

The box is already a dev box. No one else is connecting to this server  
yet, as it’s running on a non-80 port. Is there another way to debug?

Posted at Nginx Forum:

> **[Re: Rewrite help when files do NOT have a ".php" extension](https://forum.nginx.org/read.php?2,202956,203505#msg-203505)**
>
> Loving Nginx so far! So much faster and leaner than Apache. Apologies for this yet another Rewrite rule help after so many threads, but one of domains has a special need and I am struggling with Rewrite rules. The logic is simple: 1. For anything in...

---

<div class="post-metadata">

**Author:** ![pk899](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pk899](https://www.ruby-forum.com/u/pk899)\
**Post date:** [June 3, 2011, 8:41pm UTC](https://www.ruby-forum.com/t/rewrite-help-when-files-do-not-have-a-php-extension/207727/23 "2011-06-03T20:41:09Z")

</div>

## pk899 Wrote:

> any idea why? why does just port change lead to  
> this?
> 
> thanks

in my error log i am seeing messages like this:

2011/06/03 14:32:07 [error] 21125#0: \*1768 connect() failed (111:  
Connection refused) while connecting to upstream, client: 216.248.232.5,  
server: [MYDOMAIN.com](http://MYDOMAIN.com), request: “GET /itsurvey HTTP/1.1”, upstream:  
“[http://77.12.16.8:8081/itsurvey](http://77.12.16.8:8081/itsurvey)”, host: “[MYDOMAIN.com](http://MYDOMAIN.com)”

why is “upstream” connection being “refused”? and how is “upstream”  
different from “proxy”?

thanks for any ideas or advice.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,202956,203715#msg-203715](http://forum.nginx.org/read.php?2,202956,203715#msg-203715)

---

<div class="post-metadata">

**Author:** ![pk899](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pk899](https://www.ruby-forum.com/u/pk899)\
**Post date:** [June 3, 2011, 8:48pm UTC](https://www.ruby-forum.com/t/rewrite-help-when-files-do-not-have-a-php-extension/207727/24 "2011-06-03T20:48:33Z")

</div>

On 3 Jun 2011 19h40 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> different from “proxy”?  
> It’s the same thing. It’s your upstream, for which nginx is acting as  
> reverse proxy. Proxying request for scripts to Apache.

> thanks for any ideas or advice.

Check your Apache config. Paste your nginx config somewhere so that we  
can help you.

— appa

---

<div class="post-metadata">

**Author:** ![pk899](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pk899](https://www.ruby-forum.com/u/pk899)\
**Post date:** [June 3, 2011, 8:39pm UTC](https://www.ruby-forum.com/t/rewrite-help-when-files-do-not-have-a-php-extension/207727/25 "2011-06-03T20:39:17Z")

</div>

i managed to get it all installed, but the php-fpm and “location” stuff  
is just too difficult for now. will deal with that later.

right now, at least to gain from nginx serving static files and some  
bits of proxy\_cache, i did this:

1. setup nginx on port 81
2. left apache on 80 (as my site is live)

this worked. proxying was happening etc.

then, to make it live, i did this:

1. moved apache to 8081
2. moved nginx to 80
3. restarted both, first apache, then nginx

but now, with nginx being my front server, i just get 404 file not  
found.

any idea why? why does just port change lead to this?

thanks

Posted at Nginx Forum:

> **[Re: Rewrite help when files do NOT have a ".php" extension](https://forum.nginx.org/read.php?2,202956,203714#msg-203714)**
>
> Loving Nginx so far! So much faster and leaner than Apache. Apologies for this yet another Rewrite rule help after so many threads, but one of domains has a special need and I am struggling with Rewrite rules. The logic is simple: 1. For anything in...

---

<div class="post-metadata">

**Author:** ![pk899](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pk899](https://www.ruby-forum.com/u/pk899)\
**Post date:** [June 4, 2011, 6:27am UTC](https://www.ruby-forum.com/t/rewrite-help-when-files-do-not-have-a-php-extension/207727/26 "2011-06-04T06:27:01Z")

</div>

Thanks appa.

My question is: if the setup works with two ports, how come it stops  
working when the ports are switched?

Anyway, my config:

proxy\_cache\_path /dev/shm/proxy\_cache levels=1:2  
keys\_zone=proxyone:10m inactive=10m max\_size=100m;  
proxy\_cache\_key “$scheme$host$request\_uri$cookie\_\_\_user”;

proxy\_cache proxyone;  
proxy\_cache\_min\_uses 1;  
proxy\_cache\_valid any 60s;  
proxy\_cache\_valid 404 0s;  
proxy\_cache\_valid 500 502 503 504 1s;

#\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\> SERVER BLOCK

> > > > > > > > > > > > > > > > > > > > > > > > > > > > > >

server  
{  
listen 77.12.16.8:89;  
server\_name [mydomain.com](http://mydomain.com)[www.mydomain.com](http://www.mydomain.com);

```
root /home/mydomain/public_html;
index index index.php index.html;

error_page 403 = @backend;
error_page 404 = @backend;
error_page 406 = @backend;
error_page 500 = @backend;

location / {
  location

```

~.\*.(gif|jpg|png|ico|swf|rss|xml|htm|txt|js|css|gz|doc|xls|pdf)$ {  
expires max;  
try\_files $uri @backend;  
log\_not\_found off;  
}  
proxy\_pass [http://77.12.16.8:80](http://77.12.16.8:80);  
include proxy.inc;  
}

```
location @backend {
  internal;
  proxy_pass http://77.12.16.8:80;
  include proxy.inc;
}

```

} # End of server block

And in Apache:

### RPAF STUFF FOR NGINX PROXYING

LoadModule rpaf\_module modules/mod\_rpaf-2.0.so  
RPAFenable On  
RPAFproxy\_ips 127.0.0.1 77.12.16.8  
RPAFsethostname On  
RPAFheader X-Real-IP

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,202956,203802#msg-203802](http://forum.nginx.org/read.php?2,202956,203802#msg-203802)

---

<div class="post-metadata">

**Author:** ![pk899](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pk899](https://www.ruby-forum.com/u/pk899)\
**Post date:** [June 4, 2011, 6:09pm UTC](https://www.ruby-forum.com/t/rewrite-help-when-files-do-not-have-a-php-extension/207727/27 "2011-06-04T18:09:49Z")

</div>

On 4 Jun 2011 05h26 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> proxy\_cache\_key “$scheme$host$request\_uri$cookie\_\_\_user”;  
> server  
> error\_page 500 = @backend;  
> Are you sure you want to “ignore” internal server errors and instead  
> forward the request to the backend?

Note that as you have it right now the 500 status code will always be  
returned even if the request is forwarded.

> location / { location  
> ~.\*.(gif|jpg|png|ico|swf|rss|xml|htm|txt|js|css|gz|doc|xls|pdf)$ {  
> expires max; try\_files $uri @backend; log\_not\_found off; }  
> proxy\_pass [http://77.12.16.8:80](http://77.12.16.8:80); include proxy.inc; }
> 
> location @backend {

> internal;  
> ^^^^^^^^^^^

Named locations are “already” internal.  
Cf. [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpCoreModule#location)

> proxy\_pass [http://77.12.16.8:80](http://77.12.16.8:80);  
> include proxy.inc;  
> }
> 
> } # End of server block

> ### RPAF STUFF FOR NGINX PROXYING
> 
> LoadModule rpaf\_module modules/mod\_rpaf-2.0.so  
> RPAFenable On  
> RPAFproxy\_ips 127.0.0.1 77.12.16.8  
> RPAFsethostname On  
> RPAFheader X-Real-IP

I suspect that the problem is somewhere in your Apache  
configuration. Try stoping both servers and starting them  
again. Observe if the sockets are created and that each daemon is  
listening on its respective address.

lsof -i tcp or nestat -t -l

— appa

---

<div class="post-metadata">

**Author:** ![pk899](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pk899](https://www.ruby-forum.com/u/pk899)\
**Post date:** [June 5, 2011, 7:52am UTC](https://www.ruby-forum.com/t/rewrite-help-when-files-do-not-have-a-php-extension/207727/28 "2011-06-05T07:52:43Z")

</div>

Thanks appa, for bearing with me.

Yes, the VirtualHost config also needs the port to change. I had only  
changed the “Listen” port in apache.

It works now, and splendidly!

Thanks!

Posted at Nginx Forum:

> **[Re: Rewrite help when files do NOT have a ".php" extension](https://forum.nginx.org/read.php?2,202956,204025#msg-204025)**
>
> Loving Nginx so far! So much faster and leaner than Apache. Apologies for this yet another Rewrite rule help after so many threads, but one of domains has a special need and I am struggling with Rewrite rules. The logic is simple: 1. For anything in...

[Previous page](https://www.ruby-forum.com/t/rewrite-help-when-files-do-not-have-a-php-extension/207727.md?page=1)
