带有 HHVM 的 Nginx 中的 Silex 运行
Silex running in Nginx with HHVM
在 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?
你可以试试这个:
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;
}
}
在 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?
你可以试试这个:
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;
}
}