2012-08-16 104 views
1

我有一个纯HTML网站。现在我必须添加一个包含PHP文件的子目录(演示)。我将在我的nginx.conf文件中的两个位置:Nginx与PHP在一个子目录中

server { 
    listen   80; 
    server_name  mydomain.com; 

    access_log  /mydomain.com/access.log; 

    location/{ 
     root  /www; 
     index  index.html index.htm; 
    } 

    location /demo { 
     root  /www/demo; 
     index  /demo/index.php; 
    }                                                  

    location ~ /demo/.*\.php$ { 
     root  /www/demo; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php;                                                   
     fastcgi_param SCRIPT_FILENAME /www/demo$fastcgi_script_name; 
     include  fastcgi_params; 
    } 

    location ~ /\.ht { 
     deny   all; 
    } 
} 

现在mydomain.com工作得很好,但是当我试图访问mydomain.com/demo/,它一直在抱怨

No input file specified. 

这个脚本有什么问题?我想一些路径不正确设置像fastcgi_index:它应该是/demo/index.php?我试过不同的组合,但没有任何作品。任何帮助,将不胜感激!

回答

2

很可能您的fastcgi_param应该是/www$fastcgi_script_name,因为变量是完整的URI请求。 Source

+0

它的工作原理!非常感谢。 – Yang 2012-08-16 15:20:39