Old 3rd January 2011, 12:05
Paladinemishakal Paladinemishakal is offline
Junior Member
Join Date: Jan 2008
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
Default 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 {
server_name abc.com;
rewrite ^(.*) http://www.abc.com$1 permanent;

server {
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;

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;

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?

Reply With Quote
Sponsored Links
Old 4th January 2011, 14:45
falko falko is offline
Super Moderator
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,749 Times in 2,579 Posts

Have you tried to leave out this section?

location ~ ^/cms {
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx/abc_production/htdocs/cms$fastcgi_script_name;
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP cgi wrapper created with wrong paths Norman General 4 8th December 2010 15:11
Nginx on Fedora 11 Nammut HOWTO-Related Questions 1 3rd October 2009 17:35
A few nginx questions JACOBKELL Server Operation 0 15th July 2009 16:45
What's wrong with this nginx conf? JACOBKELL Server Operation 3 19th June 2009 17:15
Nginx + Apache on Ubuntu 8.04 AdamBoyle HOWTO-Related Questions 3 10th December 2008 23:54

All times are GMT +2. The time now is 10:56.

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