HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Installation/Configuration (http://www.howtoforge.com/forums/forumdisplay.php?f=4)
-   -   Nginx and PHP and Fastcgi (http://www.howtoforge.com/forums/showthread.php?t=50778)

Paladinemishakal 3rd January 2011 11:05

Nginx and PHP and Fastcgi
 
Hi All,

I am trying to migrate a website from Apache2 to Nginx. The new server is installed with Debian Lenny + Nginx 0.6.32 + PHP 5.2.6 + FastCGI.

I have the following directory structure:
1. /var/www/nginx/abc.com/htdocs - Main site
2. /var/www/nginx/abc.com/htdocs/cms - Sub site

This is my nginx vhost config:
# Redirect to www
server {
listen 0.0.0.0:80;
server_name abc.com;
rewrite ^(.*) http://www.abc.com$1 permanent;
}

server {
listen 0.0.0.0:80;
server_name www.abc.com;
root /var/www/nginx/abc_production/htdocs;
index index.php;
include /etc/nginx/fastcgi.conf;

# serve static files
location ~ ^/(cache|cms|css|img|js|language|gallery)/ {
root /var/www/nginx/abc_production/htdocs;
expires 30d;
}

location ~ ^/cms {
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx/abc_production/htdocs/cms$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}

location ~ \.php {
fastcgi_index index.php;
if ($request_filename ~ '.+\.(jpg|jpeg|gif|css|png|js|ico|html)$') { access_log off; expires 1d; }
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}

access_log /var/log/nginx/abc_production-access.log main;
error_log /var/log/nginx/abc_production-error.log;
}

This is the problem I encounter with my current vhost config:
1. Typing the URL http://www.abc.com will get the nginx to serve the correct php file index.php in /var/www/nginx/abc_production/htdocs/index.php.
2. When I try to access http://www.abc.com/cms, the server will serve me the raw content of the index.php file under /var/www/nginx/abc_production/htdocs/cms/.

I want to know how I can get nginx to serve me the sub site as the cms subdirectory contains the content management software to add stuffs to the main site. What is wrong with my nginx vhost config?

Regards.

falko 4th January 2011 13:45

Have you tried to leave out this section?

Code:

location ~ ^/cms {
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx/abc_production/htdocs/cms$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}



All times are GMT +2. The time now is 01:05.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.