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
I just wrote a howto on exactly this:
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. [email protected] 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/
Hi,
Looks like what I need - just got a little problem with the sample
file returning a 404 for: NameBright - Coming Soon
Cheers Vince,
David
Bah! Sorry about that. I fixed the URL in the article. It should be:
http://www.urbanpuddle.com/nginx.conf
cheers,
Vince
On 5/10/07, David S. [email protected] wrote:
On May 10, 3:26 pm, “Vince W.” [email protected] 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/
–
support independent business – http://www.buyindie.net/
Use /mint instead of /mint/ as the locaion and index.php instead of
/index.php as the index.
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;
}