Howto get FuelCMS working with NGINX?

edited December 2010 in Bug Reports
Hi,

Has someone got this working with Nginx and (php 5.2.x)?

I followed the instructions and got DB setup and those few configs. My problem now is that I can't log in to the admin backend.

If I go to www.domain.com/fuel --> it will redirect to domain.com/fuel/login/4c325a315a57773d which is ok. But if I enter admin / admin I will be redirected back to login page? (If entered something else I will get login error)

I am there stuck and I will not get into admin backend. Any clues what is going wrong?

I have tried with master and 0.91 version and both gives the same result.

When pressing login (when entered user & pass) it will:
post form to /fuel/login/4c325a315a57773d --> which will 302 redirect to /fuel
Which will 302 to /fuel/login/4c325a315a57773d

I will get ci_session cookie and fuel_something where value = 1 when trying to login.

This is needed for Nginx + php-fpm to get codeigniter to work at all.
fuel/application/config/config.php
$config['uri_protocol'] = "REQUEST_URI";

Here are the most important part of my Nginx configs:

#RewriteRule ^(fuel/modules/(.+)?/assets/(.+)) - [L]
if (!-f $request_filename) {
rewrite ^/(.*)(fuel/modules/.*) /$2 last;
rewrite ^/(.*)(/assets/.*) /$2 last;
}

location ^~ /fuel/crons {
deny all;
}
location ^~ /fuel/data_backup {
deny all;
}

# Do not allow direct access to the CodeIgniter front controller
location ~* ^/index.php {
rewrite ^/index.php/?(.*)$ /$1 permanent;
}

location / {
try_files $uri @codeigniter;
}

# CodeIgniter Front Controller
location @codeigniter {
internal;
fastcgi_pass php_socket;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/conf/fastcgi_config_ci;
include /etc/nginx/conf/fastcgi_params_ci;
fastcgi_param SCRIPT_NAME index.php;
fastcgi_param SCRIPT_FILENAME /var/www/fuelcmssitefolder/index.php;
}

Comments

  • edited 5:49PM
    I'm not familiar with NGINX, however, you could try putting in the $config['index_page'] = 'index.php'; in the fuel/application/config/config.php file. This will add index.php to your URIs but should at least work.
  • edited 5:49PM
    I tried that also, but it does not change anything.

    I couldn't find where the authentication is happening e.g. when getting /fuel/ url after login post? Any hint where to look. I could try to add some traces to see why it does not authenticate even tough it should.

    Is FuelCMS using /index.php file as only front controller which should be loaded to PHP or is there some other front controllers also? E.G. there is this index.php in /fuel/ folder also... which is not accessed by my nginx conf at the moment.
  • edited 5:49PM
    I got a bit time to debug further... things almost work (If hacked a bit, real reason not found yet). When loading /fuel/dashboard page it will initialize two XMLHttpRequest from jQx (DashboardController.js). First one /fuel/dashboard/ajax goes ok, but second one /backup/dashboard request will fail in user authentication and will give 302 header which redirects the browser back to login page, doh.

    This /backup/dashboard fails in cookie checking. For some reason this cookie fuel_(md5(site name)) is not set for this request as it was for the previous one.

    Any ideas why this is failing?

    ... and of course... this cookie fuel_(md5(site_name)) has path /fuel... which obviously is not used when requesting /backup/dashboard ... so this is bug in FuelCMS after all and not Nginx issue.

    Maybe backup/dashboard should be routed trough /fuel/backup/dashbord, right?
  • edited 5:49PM
    With regards to your question about a second front controller, FUEL only uses the standard index.php as the front controller. The fuel/index.php is just a header redirect so that if you navigation to /fuel/ it will redirect you to the dashboard.

    The dashboard ajax requests to /backup/dashboard should work and is the actual URI location. FUEL actually creates routes so that /fuel/backup/dashboard works.

    The get_session_namespace method in Fuel_auth uses the fuel config value site_name (see the fuel/application/config/MY_fuel.php) so that there isn't session interference between multiple installations of FUEL on the same server.

    It sounds like you are having trouble with the session getting set correctly so you get redirected. The session is using the CI sessions which uses a cookie instead of the native $_SESSION variable. I would first delete any localhost cookies that may pertain to the FUEL install and restart your browser and test again. Then, if you are still having troubles, I've found the following library to sometimes be useful that is a drop in replacement for the CI Session class which uses the $_SESSION variable (goes in fuel/application/libraries/ folder).
    http://codeigniter.com/wiki/Category:Libraries::Session/

    Try that out to see if you can't get the session working correctly.
  • edited 5:49PM
    Finally got things sorted out, and it was the Nginx config that was causing troubles.

    The problem was that the $_SERVER['SCRIPT_NAME'] was only returning "index.php" and code needed the "/index.php" to be working properly. Without slash "/" WEB_PATH constant was empty and it was used to set login cookie path. If there was not path then it was defaulted to current path which was "/fuel". This caused that this cookie was not set when getting /backup/desktop which is checked with is_fuelified() function.

    When I get all bits sorted out from nginx config, I'll post an example one to be used with FuelCMS.

    Quick fix was to change SCRIPT_NAME like this:
    fastcgi_param SCRIPT_NAME /index.php;
  • edited 5:49PM
    Excellent! Thanks for sticking with it and looking forward to the post.
  • edited 5:49PM
    Hey thanks very much. Adding the forward slash in the WEB_PATH worked :))
Sign In or Register to comment.