Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
fuelphp nginx vhost config
  • FuelPHP seems to work fine with my old nginx config for kohana. How come the rewrite is working (or rather, is it suppose to work) with index.php/?kohana_uri=$1 - Can anyone make some recommendations for my config below?
    server {
    listen   80;
    server_name mydomain.com;
    
    access_log /home/mydomain.com/log/access.log;
    error_log /home/mydomain.com/log/error.log;
    
    root   /home/mydomain.com/public/;
    index  index.php index.html;
    charset utf-8;
    
    # Gzip
    gzip on;
    gzip_min_length 1000;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_disable "MSIE [1-6]\.";
    
    location ~ /\. {
     return 404;
    }
    
    location /  {
     if (-f $request_filename) {
       break;
     }
     if (-d $request_filename) {
       break;
     }
     rewrite ^/(.+)$ /index.php?kohana_uri=$1 last;
    }
    
    location ~ \.php$ {
     fastcgi_pass   127.0.0.1:9000;
     fastcgi_index  index.php;
     fastcgi_param  SCRIPT_FILENAME  /home/mydomain.com/public/$fastcgi_script_name;
     include /usr/local/nginx/conf/fastcgi_params;
    }
    
    location ~* ^/(modules|application|system) {
     return 403;
    }
    
    }
    
  • anyone want to post a working fuelphp config for nginx?
  • Dan H. blog: http://www.serversidemagazine.com/community/getting-nginx-up-and-running/ server { listen 80;
    server_name dev.george;
    access_log /var/log/nginx/localhost.access.log; root /var/www;
    index index.php; location / {
    # so first, let's try to see if the file exists, if not, does a dir exist,
    # and finally if neither, pass it to our handler
    try_files $uri $uri/ @handler;
    expires 30d;
    } ## Images and static content is treated different
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
    access_log off;
    } # This is where you set your rewrites
    # this one works on Fuel and CodeIgniter
    location @handler {
    rewrite ^ /index.php?/$request_uri;
    } location ~ \.php$ { #escape that period, yo
    expires off;
    fastcgi_split_path_info ^(.+\.php)(.*)$; #if you're using PATH_INFO (as indicated above), you need to pass that to FCGI like this:
    fastcgi_param PATH_INFO $fastcgi_path_info; #pass to socket
    fastcgi_pass unix:/tmp/php.socket; include fastcgi_params; fastcgi_intercept_errors on;
    fastcgi_ignore_client_abort off;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    } location /. {
    deny all;
    }
    }
  • Dan H. blog: http://www.serversidemagazine.com/community/getting-nginx-up-and-running/ server { listen 80;
    server_name dev.george;
    access_log /var/log/nginx/localhost.access.log; root /var/www;
    index index.php; location / {
    # so first, let's try to see if the file exists, if not, does a dir exist,
    # and finally if neither, pass it to our handler
    try_files $uri $uri/ @handler;
    expires 30d;
    } ## Images and static content is treated different
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
    access_log off;
    } # This is where you set your rewrites
    # this one works on Fuel and CodeIgniter
    location @handler {
    rewrite ^ /index.php?/$request_uri;
    } location ~ \.php$ { #escape that period, yo
    expires off;
    fastcgi_split_path_info ^(.+\.php)(.*)$; #if you're using PATH_INFO (as indicated above), you need to pass that to FCGI like this:
    fastcgi_param PATH_INFO $fastcgi_path_info; #pass to socket
    fastcgi_pass unix:/tmp/php.socket; include fastcgi_params; fastcgi_intercept_errors on;
    fastcgi_ignore_client_abort off;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    } location /. {
    deny all;
    }
    }
  • Here you go: http://stackoverflow.com/questions/376732/zend-framework-on-nginx/4470469#4470469 I have verified this works with Fuel. (FYI, any half decent config for Zend will be fine with Fuel.)
  • i use the ff. on my fuel on nginx on windows, i hope it helps: http://tinypaste.com/5468a
  • https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/ In the above article it explains certain configurations from tutorials of Nginx that may cause a vulnerability, read over it if you are running Nginx.
  • location / {
    if (-f $request_filename) {
    break;
    }
    if (-d $request_filename) {
    break;
    }
    rewrite ^/(.+)$ /index.php?kohana_uri=$1 last;
    } You can completely replace that entire block with: location / {
    try_files $uri $uri/ /index.php?$uri;
    } Also you can make the following changes to prevent anything except index.php being run:
    location ~ ^/index.php$ {
    allow all;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    location ~ \.php$ {
    deny all;
    }
  • Foo Bar wrote on Sunday 1st of May 2011:
    404
    probably url was too long.. no? shortened here: http://bit.ly/hEFAin
  • Andrew Smith wrote on Saturday 20th of August 2011:
    Here is my nginx config http://scrp.at/age I haven't had any trouble with it to date. The only thing I am yet to figure is how to setEnv in a nginx config. Note: The client_max_body_size and client_body_buffer_size are optional, I needed them in order to upload large video files in a specific project.

    Setting environment / application variables in nginx is as easy as: fastcgi_param FUEL_ENV staging
  • Here is my nginx config http://scrp.at/age I haven't had any trouble with it to date. The only thing I am yet to figure is how to setEnv in a nginx config. Note: The client_max_body_size and client_body_buffer_size are optional, I needed them in order to upload large video files in a specific project.
  • Hello everyone, can you guys share more configs for nginx + fuelphp? Because I can't find any working example to work with uris which contain the ' : ' in them.
    All paths are working, every part of the site is working nicely but not the urls with ' : ' inside the uri string Thank you
  • Jaroslav Petrusevic wrote on Saturday 20th of August 2011:
    Because I can't find any working example to work with uris which contain the ' : ' in them.
    All paths are working, every part of the site is working nicely but not the urls with ' : ' inside the uri string

    The nginx location blocks I linked above work with variable URL paths. e.g.
    https://www.moochd.com/blog/variable1/variable2 app/config/routes.php:
    <?php
    return array(
            'blog/:test/:womble' => 'welcome/entry',
    );
    ?>
    

    app/controller/welcome.php:
    <?php
    class Controller_Welcome extends Controller {
    
     public function action_entry()
     {
      echo "<h1>Test = ".$this->param('test')."</h1>";
      echo "<h1>Womble = ".$this->param('womble')."</h1>";
     }
    }
    

    If you can give me some examples of these URL's I'm sure I can give you some hints on how to solve the location/rewrite issues in Nginx.
  • Jaroslav Petrusevic wrote on Saturday 20th of August 2011:
    Hello everyone, can you guys share more configs for nginx + fuelphp? Because I can't find any working example to work with uris which contain the ' : ' in them.
    All paths are working, every part of the site is working nicely but not the urls with ' : ' inside the uri string Thank you

    Have you tried all the listed nginx configs? This works with the nginx config I posted. If I am correct you are asking about urls like http://www.domain.com/hello/world:me/ ?
  • Guys it's seems to be a bug, I have filled out the issue now: https://github.com/fuel/core/issues/414
    Let's see how it goes! :) and thank you everyone
  • change:
    rewrite ^/(.+)$ /index.php?kohana_uri=$1 last; to:
    rewrite ^/(.+)$ /index.php/$1 last; remove:
    'index.php' from your config file base url. This routes the uri to /index.php/{uri}... if you're using this for test purposes you could always just remove the rewrites all together and your urls would look like this. http://mydomain.com/index.php/controller/action ...
  • Scratch rewrite rules, use the try_files directive instead. mod_rewrite is meant as a last resort. The Apache equivalent is called FallbackResource. It should also be possible to set the handler on the directory to whatever you use for php (using mod_action) and alias /assets for default-handler which would save 1 expensive stat (the filesystem has to search before drawing the ENOENT conclusion) per static file request (going on a limb here, do your own research). I tend to avoid Apache though, because the current stable version lacks a builtin FastCGI module (2.4 will have a fully supported mpm_event and mod_proxy_fastcgi, good stuff).

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion