0

Installed HHVM on Nginx. Plain PHP and HH files are working fine.

Now I am going to wrap the site with Silex.

Installed Silex and now changed the Nginx default site conf to this based on Silex documentation: 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;
        }
}

Now it simply won't work. "/" and "/code" visits all gives me a 502 error.

Any hints?

UPDATE

Now I changed the fastcgi_pass from unix:/var/run/php-fpm/www.sock to 127.0.0.1:9000 and new issues.

  1. Visiting "/" is OK.
  2. Visiting "/lib"is 404.

My Silex code like this:

$app->get('/lib', function() use ($app)
{
    $dir=__DIR__;
    return $app['twig']->render('index.html.twig');
});

I have tried to put an .htaccess in the root directory but no help.

2nd UPDATE

I have changed my Silex code a bit:

$app->get('lib/', function() use ($app)
{
    $dir=__DIR__;
    dump($dir);die();
});

Now if I visited "localhost/lib/", still 404, but, "localhost/index.php/lib" is working fine.

The 404 page screen shot is attached. It seems like the Nginx internal 404?

enter image description here

TaylorR
  • 3,746
  • 5
  • 25
  • 42
  • This might help you. http://stackoverflow.com/a/16497957/1920638 – MrTechie Apr 06 '15 at 04:08
  • Thanks. This solves the first step issue. I will update my question because there are more issues. – TaylorR Apr 06 '15 at 05:12
  • What's giving the 404, your script or the web server? – Ja͢ck Apr 06 '15 at 05:21
  • You are declaring the URL wrongly, put the slash on the begining: ```$app->get('/lib/', function() { ...});``` (the last slash is optional depending if you want to do *localhost/lib* or *localhost/lib/* – mTorres Apr 06 '15 at 07:46
  • @mTorres Sorry but it is not true. Changed to `$app->get('/lib')` and/or created a few other testing route like `$app->get('/lib2')`. They are accessible via `localhost/index.php/lib` or `localhost/index.php/lib2` but not accessible without the `index.php` portion. – TaylorR Apr 06 '15 at 08:11

1 Answers1

1

You can try this:

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;
    }
}
raptor.zh
  • 1,020
  • 7
  • 7