我一直在本地开发环境(Vagrant+Virtualbox)中与Phalcon合作一个项目。它工作得很好,我的开发时间真的减少了。
现在我想把这个项目放在Plesk 11.5 nginx环境中,我遇到了在Plesk中为Phalcon配置nginx的问题。我对Nginx也很陌生。
我有以下Nginx配置:
server {
listen 80;
server_name localhost.dev;
index index.php index.html index.htm;
set $root_path '/var/www/httpdocs';
root $root_path;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ '.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+'.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /'.ht {
deny all;
}
}
我删除了"服务器{}",因为Plesk nginx配置中不允许使用这些。然而,它就是不起作用。应用程序的主页显示得很完美,所以Phalcon运行得很好,但路由不起作用:/search只给出了一个404,它在我的本地环境中使用此配置确实起作用。
我应该在Plesk中更改什么才能使其工作?
感谢您提前抽出时间!
首先检查PHP是否通过PHP-FPM或Apache对域进行处理。
如果你使用nginx就像apache的反向代理和apache处理的PHP一样,你只需要将Phalcon bootstrap index.PHP和.htaccess放在/var/www/vhosts/domain.tld/httpdocs中,并将所有其他应用程序文件放在/var/www/vhosts/domain.tld中(我已经成功地运行了Phalcon教程中的这种配置)
在PHP-FPM的情况下,最简单的方法是定义自定义虚拟主机模板
mkdir -p /usr/local/psa/admin/conf/templates/custom/domain
cp /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain/
在/usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php中,为您的域名设置条件,只需响应完整的配置,如:
<?php if $VAR->domain->asciiName == 'your-domain.tld' ?>
plain text of your full nginx config here
<?php else: ?>
plesk default instruction for all other domains
<?php endif ?>