Phraw Official Forum

The discussions here are for Phraw, a micro framework for the PHP programming language.

Return to the Phraw home.

You are not logged in.

#1 2011-10-22 16:59:02

davmuz
Admin
From: Maranello, Italy
Registered: 2011-08-18
Posts: 23
Website

Nginx support

I did a test on Ubuntu Server 11.10 + Nginx 1.0.5 + PHP 5.3.6 with spawn-
fcgi.

Phraw (dev) runs well. wink

Make sure to add these lines to the Nginx configuration of your web site:

location / {
    # ...

    if (!-f $request_filename) {
        rewrite ^.*$ /index.php last;
        break;
    }
    if (!-d $request_filename) {
        rewrite ^.*$ /index.php last;
        break;
    }

    # ...
}

Offline

#2 2012-01-21 11:32:43

osb
Member
Registered: 2012-01-21
Posts: 2

Re: Nginx support

I tried this and the initial home page showed up but the routes and 404 pages are not working.

Offline

#3 2012-01-21 17:22:23

davmuz
Admin
From: Maranello, Italy
Registered: 2011-08-18
Posts: 23
Website

Re: Nginx support

What Phraw version are you using? Could you post here routing code?

Offline

#4 2012-01-21 22:20:44

osb
Member
Registered: 2012-01-21
Posts: 2

Re: Nginx support

My stack is Ubuntu/Nginx (1.0.2)/PHP5-FPM And I tried other micro frameworks without any issues like silex and slim php framework.

if ($phraw->detect_no_trailing_slash()) { # This fix the trailing slash
    $phraw->fix_trailing_slash();
} else if ($phraw->route('')) { # Example of dynamic page
    require('./resources/views.php');
    home($phraw, $raintpl);
} else if ($phraw->bulk_route($static_pages, $page)) { # Example of static pages in bulk
    $raintpl->draw($page);
} else { # The page does not exist: display error 404
    $raintpl->display_error();
}

I tried both Phraw 0.3 and 0.4 with the same issue. Home page shows but other routes and 404 does not work.

Last edited by osb (2012-01-21 22:21:43)

Offline

#5 2012-01-23 15:37:28

davmuz
Admin
From: Maranello, Italy
Registered: 2011-08-18
Posts: 23
Website

Re: Nginx support

Hi Osb,
I see that you are using the default regular expression algorithm for bulk_route(), so your $static_pages should be like (Phraw 0.4rc):

$static_pages = array(
    '^$' => 'index.html',
    '^about\/$' => 'about.html',
    '^contacts\/$' => 'contacts.html',
    '^documentation\/$' => 'documentation/index.html'
);

Is this?

If you don't want to use regular expressions, but very simple and plain URLs, just add the "equal" parameter to bulk_route():

...
} else if ($phraw->bulk_route($static_pages, $page, 'equal')) {
...

Offline

Board footer

Powered by FluxBB