Nginx,PHP-FPM,在子程序中有2个应用程序

我有2个应用程序在2个不同的文件夹。 我想使用根文件夹除了/ SOMENAME作为URL中的文件夹,在这种情况下,我想指向该文件夹。

我尝试了几个位置/别名块,但没有一个工作(位置是正确的,但PHP文件没有提供只有静态内容)…看到我的configuration下面。

server { listen 80; #disable_symlinks off; server_name join.mydomain.com; #allow few domains root /www/main; #removing the 'index.php' location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php; } index index.html index.php; } location /SOMENAME/ { root /www/somename; } ####################### location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param HTTPS on; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } 

您有两个PHP应用程序,托pipe在不同的文档根目录中,这意味着您需要两个location ~ \.php$块。 假设SOMENAMEsomename实际上是一样的,你可以使用这样的东西:

 root /www/main; index index.html index.php; location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; } location ^~ /somename { root /www; try_files $uri $uri/ /somename/index.php; location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; } } 

location指令上的^~修饰符,使得​​这个前缀位置优先于它上面的正则expression式位置块,所以PHP脚本被正确的位置块处理。 详情请参阅此文件 。

这里logging了 try_files指令。