【问题标题】:Silex running in Nginx with HHVM使用 HHVM 在 Nginx 中运行的 Silex
【发布时间】: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_passunix:/var/run/php-fpm/www.sock 更改为 127.0.0.1:9000 和新问题。

  1. 访问“/”是可以的。
  2. 访问“/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/liblocalhost/index.php/lib2 访问,但如果没有index.php 部分则无法访问。

标签: php nginx silex


【解决方案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;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 2014-01-29
    • 1970-01-01
    • 1970-01-01
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多