在Nginx上安装了HHVM。普通的PHP和HH文件工作正常。
现在我要用Silex封装网站。
安装了Silex,现在根据Silex文档将Nginx默认站点conf更改为此:http://silex.sensiolabs.org/doc/web_servers.html#nginx
server {
root /vagrant/hhvm;
#site root is redirected to the app boot script
location = / {
try_files @site @site;
}
#all other locations try other files first and go to our front controller if none of them exists
location / {
try_files $uri $uri/ @site;
}
#return 404 for all php files as we do have a front controller
location ~ \.php$ {
return 404;
}
location @site {
fastcgi_pass unix:/var/run/php-fpm/www.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
#uncomment when running via https
#fastcgi_param HTTPS on;
}
}
现在它根本行不通。 “/”和“/ code”访问都给了我502错误。
任何提示?
更新
现在我将fastcgi_pass
从unix:/var/run/php-fpm/www.sock
更改为127.0.0.1:9000
以及新问题。
我的Silex代码如下:
$app->get('/lib', function() use ($app)
{
$dir=__DIR__;
return $app['twig']->render('index.html.twig');
});
我试过在根目录中放一个.htaccess
但没有帮助。
第二次更新
我稍微更改了我的Silex代码:
$app->get('lib/', function() use ($app)
{
$dir=__DIR__;
dump($dir);die();
});
现在如果我访问了“localhost / lib /”,仍然是404,但是,“localhost / index.php / lib”工作正常。
附上404页面截图。看起来像Nginx内部404?
答案 0 :(得分:1)
你可以试试这个:
server {
root /vagrant/hhvm;
index index.php;
location / {
try_files $uri $uri/ /index.php?args;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php last;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#uncomment when running via https
#fastcgi_param HTTPS on;
}
}