Getting Django & PHP to work together
Mihir Joshi
lists at ruby-forum.com
Tue Apr 1 04:34:12 MSD 2008
Hi,
I'm trying to get Django & PHP to work together on one Virtual Host.
PHP5 + FastCGi works flawlessly on Nginx 0.6.29, but when I add Django,
I have trouble loading files which are index.html or index.php.
Please help me solve this problem. Thanks!
My Virtual Host conf is as shown below.
server {
listen 80;
server_name www.example.com;
rewrite ^/(.*) http://example.com/$1 permanent;
}
server {
listen 80;
server_name example.com;
location / {
root /home/username/example.com/public/;
index index.html index.php;
}
# Serve static files directly
location ~*
^.+\.(html|jpg|jpeg|gif|png|bmp|ico|js|css|zip|xml|xsl|tgz|gz|rar|bz2|doc|docx|xls|xlsx|rtf|pdf|ppt|txt|tar|exe|mid|midi|wav|mpg|avi|mp3|swf|mpeg)$
{
root /home/username/example.com/public/;
limit_rate 2000K;
expires 30d;
break;
}
# Pass requests to Django if the file is not Static or PHP
location / {
if (-f $request_filename) {
break;
}
if (-d $request_filename) {
index index.html index.php;
break;
}
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
# host and port to fastcgi server
fastcgi_pass 127.0.0.1:8801;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
# pass the PHP scripts to FastCGI server listening on
# 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/home/username/example.com/public$fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}
# redirect file not found errors to /error.php
error_page 404 /error.php;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
rewrite ^/photo/(.*)$ /get_photo.php?pid=$1 last;
# deny access to .svn folders
location ~ /\.svn {
deny all;
}
}
--
Posted via http://www.ruby-forum.com/.
More information about the nginx
mailing list