我想在这样的子文件夹上运行 PhalconPHP 应用程序http://stg.example.org/simon/apps/phalconapp/
我的 Nginx 配置片段如下...
location ^~ /simon/apps/phalconapp {
root /var/www/stg.example.org/simon/apps/phalconapp/public;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
然而,我得到了文件未找到尝试访问应用程序时出错。我可能做错了什么?
========= 更新的配置
location ^~ /simon/apps/phalconapp {
alias /var/www/stg.example.org/simon/apps/phalconapp/public;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
if (!-e $request_filename) {
rewrite ^ /simon/apps/phalconapp/public/index.php?_url=/$1 last;
}
location ~ \.php$ {
if (!-f $request_filename) {
rewrite ^ /simon/apps/phalconapp/public/index.php?_url=/$1 last;
}
fastcgi_pass 127.0.0.1:9000; #set port for php-fpm to listen on
fastcgi_index index.php;
try_files $uri =404;
include fastcgi_params;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
location @rewrite {
rewrite ^/(.*)$ /simon/apps/phalconapp/public/index.php?_url=/$1;
}
======= 几乎可以正常工作的配置 2
location ^~ /simon/apps/phalconapp {
alias /var/www/stg.example.org/simon/apps/phalconapp;
index index.php index.html;
try_files $uri $uri/ @rewrite;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
include /etc/nginx/fastcgi_params;
}
}
location @rewrite {
rewrite ^/(.*)$ /simon/apps/phalconapp/public/index.php?_url=/$1;
}
答案1
此配置对我有用。不过,如果有人能更了解 Nginx 配置,我将不胜感激。
location ^~ /simon/apps/phalconapp {
alias /var/www/stg.example.org/simon/apps/phalconapp;
index index.php index.html;
try_files $uri $uri/ @rewrite;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
include /etc/nginx/fastcgi_params;
}
}
location @rewrite {
rewrite ^/simon/apps/phalconapp(.*)$ /simon/apps/phalconapp/public/index.php?_url=$1 ;
}