【发布时间】:2015-06-10 11:47:11
【问题描述】:
在 Nginx 上安装了 HHVM。普通的 PHP 和 HH 文件工作正常。
现在我要用 Silex 来包装网站。
安装了 Silex,现在根据 Silex 文档将 Nginx 默认站点配置更改为: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 和新问题。
- 访问“/”是可以的。
- 访问“/lib”是404。
我的 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?
【问题讨论】:
-
这可能会对您有所帮助。 stackoverflow.com/a/16497957/1920638
-
谢谢。这解决了第一步的问题。我会更新我的问题,因为还有更多问题。
-
404 的原因是什么,你的脚本还是网络服务器?
-
您错误地声明了 URL,将斜杠放在开头:
$app->get('/lib/', function() { ...});(最后一个斜杠是可选的,具体取决于您要执行 localhost/lib 还是 localhost/lib/ -
@mTorres 抱歉,这不是真的。更改为
$app->get('/lib')和/或创建了一些其他测试路线,例如$app->get('/lib2')。它们可通过localhost/index.php/lib或localhost/index.php/lib2访问,但如果没有index.php部分则无法访问。