# Nginx+mongrel also serving up php

**URL:** <https://www.ruby-forum.com/t/nginx-mongrel-also-serving-up-php/103810>\
**Category:** Deployment\
**Created:** [May 10, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-also-serving-up-php/103810 "2007-05-10T15:34:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [May 10, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-also-serving-up-php/103810/1 "2007-05-10T15:34:17Z")

</div>

I’ve been following some tutorials and things from the Nginx english  
documentation and have it successfully serving up static content and  
proxying to mongrel for rails requests. This is all working fine.

However, I have some php I want to run (Mint) inside my rails app and  
I cannot for the life of me get this to work properly.

 server { # port to listen on. Can also be set to an IP:PORT listen 80;

```
# Set the max size for file uploads to 50Mb
client_max_body_size 50M;

# sets the domain[s] that this vhost server requests for.
# None means listen to all.
server_name www.davidsmalley.com davidsmalley.com;

# doc root
root /u/apps/davidsmalley.com/public;
index index.html index.htm index.php;

# vhost specific access log
access_log /var/log/nginx.vhost.davidsmalley.access.log main;

# this rewrites all the requests to the maintenance.html
# page if it exists in the doc root. This is for capistrano's
# disable web task
if (-f $document_root/system/maintenance.html) {
  rewrite ^(.*)$ /system/maintenance.html last;
  break;
}

location ~ .php$ {
  fastcgi_pass 127.0.0.1:9000;
   fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME /u/apps/davidsmalley.com/public

```

$fastcgi\_script\_name;  
fastcgi\_param QUERY\_STRING $query\_string;  
fastcgi\_param REQUEST\_METHOD $request\_method;  
fastcgi\_param CONTENT\_TYPE $content\_type;  
fastcgi\_param CONTENT\_LENGTH $content\_length;  
fastcgi\_param REDIRECT\_STATUS 200;  
}

```
location / {

```

- all the code from here on works fine and just proxies to my  
mongrel cluster

I have php spawned as an FCGI running locally on port 9000 - it shows  
up in netstat/ps and I can telnet to it.

For some reason, attempting to hit /mint/index.php just causes my  
browser to receive a download of index.php rather than rendering it on  
screen.

So, has anyone got any tips for how to serve mint properly in this  
situation - or some pointers as to how I can check I am proxying  
correctly to fast-cgi

Much appreciated,

David

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [May 10, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-also-serving-up-php/103810/2 "2007-05-10T16:27:25Z")

</div>

I just wrote a howto on exactly this:  
[http://www.urbanpuddle.com/articles/2007/05/09/install-ruby-on-rails-on-ubuntu-feisty-fawn](http://www.urbanpuddle.com/articles/2007/05/09/install-ruby-on-rails-on-ubuntu-feisty-fawn)

sample conf files included…

-Vince

On 5/10/07, David S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> # port to listen on. Can also be set to an IP:PORT
> root /u/apps/davidsmalley.com/public;
> break;
> fastcgi_param CONTENT_LENGTH $content_length;
> 
> ```
> 
> For some reason, attempting to hit /mint/index.php just causes my
> 
> >

–  
support independent business – [http://www.buyindie.net/](http://www.buyindie.net/)

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [May 10, 2007, 4:39pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-also-serving-up-php/103810/3 "2007-05-10T16:39:30Z")

</div>

Hi,

Looks like what I need - just got a little problem with the sample  
file returning a 404 for: [NameBright - Coming Soon](http://www.urbanpuddle.com/public/nginx.conf)

Cheers Vince,

David

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [May 10, 2007, 4:44pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-also-serving-up-php/103810/4 "2007-05-10T16:44:30Z")

</div>

Bah! Sorry about that. I fixed the URL in the article. It should be:

[http://www.urbanpuddle.com/nginx.conf](http://www.urbanpuddle.com/nginx.conf)

cheers,  
Vince

On 5/10/07, David S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On May 10, 3:26 pm, “Vince W.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > ```
> > > # port to listen on. Can also be set to an IP:PORT
> > > root /u/apps/davidsmalley.com/public;
> > > break;
> > > fastcgi_param CONTENT_LENGTH $content_length;
> > > 
> > > ```
> > > 
> > > For some reason, attempting to hit /mint/index.php just causes my
> > 
> > –  
> > support independent business –[http://www.buyindie.net/](http://www.buyindie.net/)
> 
> >

–  
support independent business – [http://www.buyindie.net/](http://www.buyindie.net/)

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [May 10, 2007, 11:56pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-also-serving-up-php/103810/5 "2007-05-10T23:56:53Z")

</div>

Use /mint instead of /mint/ as the locaion and index.php instead of  
/index.php as the index.

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [May 10, 2007, 7:10pm UTC](https://www.ruby-forum.com/t/nginx-mongrel-also-serving-up-php/103810/6 "2007-05-10T19:10:04Z")

</div>

Hmm - I’ve got one small problem with my setup if anyone can shed any  
light…

/mint/ - downloads the contents of index.php

//mint/ - loads the page properly.

(a snippet of…) my config looks like this

```
location /mint/ {
  index /index.php;
}

location / {
  # Uncomment to allow server side includes so nginx can
  # post-process Rails content
  ## ssi on;

  # needed to forward user's IP address to rails
  proxy_set_header X-Real-IP $remote_addr;

  # needed for HTTPS
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_redirect false;
  proxy_max_temp_file_size 0;

  # If the file exists as a static file serve it directly without
  # running all the other rewite tests on it
  if (-f $request_filename) {
    break;
  }

  # check for index.html for directory index
  # if its there on the filesystem then rewite
  # the url to add /index.html to the end of it
  # and then break to send it to the next config rules.
  if (-f $request_filename/index.html) {
    rewrite (.*) $1/index.html break;
  }

  # Look for existence of PHP index file.
  # Don't break here...just rewrite it.
  if (-f $request_filename/index.php) {
    rewrite (.*) $1/index.php;
  }

  # this is the meat of the rails page caching config
  # it adds .html to the end of the url and then checks
  # the filesystem for that file. If it exists, then we
  # rewite the url to have explicit .html on the end
  # and then send it on its way to the next config rule.
  # if there is no file on the fs then it sets all the
  # necessary headers and proxies to our upstream mongrels
  if (-f $request_filename.html) {
    rewrite (.*) $1.html break;
  }

  if (!-f $request_filename) {
    proxy_pass http://ds_mongrels;
    break;
  }
}

error_page 500 502 503 504 /500.html;
location = /500.html {
  root /u/apps/davidsmalley.com/public;
}

location ~ \.php$ {
  fastcgi_param QUERY_STRING $query_string;
  fastcgi_param REQUEST_METHOD $request_method;
  fastcgi_param CONTENT_TYPE $content_type;
  fastcgi_param CONTENT_LENGTH $content_length;
  fastcgi_param REDIRECT_STATUS 200;
  fastcgi_pass unix:/tmp/fcgi.sock;
   fastcgi_index /index.php;
  fastcgi_param SCRIPT_FILENAME /u/apps/davidsmalley.com/public/

```

$fastcgi\_script\_name;

```
}
```
