Welcome Guest, Not a member yet? Register   Sign In
codeigniter + nginx + php-fpm
#1

[eluser]luisfmgoncalves[/eluser]
Hey guys.

I developed a webpage with codeigniter and apache. I use Ubuntu in the computer I developed the application.
After that and when I try to upload to the production server, the system administration told me that the application should run in nginx and with php-fpm. Oh, and he told me that the Linux distribuiton is CentOS.
Since that moment I realized that I will get problems for sure.

So, after I upload the project to the server, I get a 504 Gateway Timeout . And the good thing is that I don't have access to the nginx error.log... O.O

Anyway, after this, I decided to install the same version of nginx and php in the computer I developed (with Ubuntu) and make it work and after that upload the project the server. I make it work in my computer but was still not working in the server.

I decided to upload a clean version of codeigniter and started to had code till I get the error. With this method I realized that something was not working properly.

In the project I have a template view with the following code:

Code:
<?php
$this->load->view('include/header_view');
$this->load->view($main_content);
$this->load->view('include/footer_view');
?>

where $main_content is a variable that I assign with whatever I want.

But, the problem is that in the server this line:

Code:
$this->load->view('include/header_view');

simple don't work! Looks like I can't load a view from another view. I don't know if this is something related with paths...
Maybe is a CentOS thing, because in my Ubuntu everything works good with nginx and php-fpm. I'm not a Red Hat user, so maybe I'm missing something...

I also tried to load the header from the same folder:

Code:
$this->load->view('header_view');

But doesn't work.
If I call directly the header_view file, than works fine!

This is something I can change... I just need to rewrite some views and I make it work...
But I'm curious about what is wrong!

My nginx.conf file is like this:

Code:
server {
access_log  /var/log/nginx/localhost.access.log;
root /var/www/project;
server_name domain.com;

    # enforce NO www
if ($host ~* ^www\.(.*)){
    set $host_without_www $1;
    rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}

if ($request_uri ~* ^(/home(/index)?|/index(.php)?)/?$){
    rewrite ^(.*)$ / permanent;
}

if ($request_uri ~* index/?$){
    rewrite ^/(.*)/index/?$ /$1 permanent;
}

if (!-d $request_filename){
    rewrite ^/(.+)/$ /$1 permanent;
}

error_page 404 /index.php;

location / {
    root   /var/www/project;
    index  index.php;
}

location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
  access_log        off;
  expires           30d;
  root /var/www/project;
}

## Parse all .php file in the /var/www directory
    location ~ .php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/project$fastcgi_script_name;
    include fastcgi_params;
    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;
    fastcgi_intercept_errors on;
}

## Disable viewing .htaccess & .htpassword
     location ~ /\.ht {
         deny  all;
     }
}
upstream backend {
        server 127.0.0.1:9000;
}

Is the problem related with this configuration?
Any of you had this problem before?

Thanks,

Luis

P.S.:
PHP 5.3.3 (php modules from remi repositories)
CentOS 5.5
mysql
Codeigniter 1.7.2
#2

[eluser]bretticus[/eluser]
The problem is not codeigniter and there's nothing you can do with your code to get it working. Case in point, it works fine on your installation but not on the server. You will most likely need to get into contact with the administrator for nginx.

By the way, here's a snippet of my nginx php-fpm codeiniter config. Works great.

Code:
location / {
    
        root  /opt/directories/the_site/public/;
        index  index.php;

        # this serves static files that exist without running other rewrite tests
                if (-f $request_filename) {
                    expires 30d;
                    break;
                }

                # this sends all non-existing file or directory requests to index.php
                if (!-e $request_filename) {
                        rewrite ^(.+)$ /index.php?$1 last;
                }
    }
    
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
        access_log        off;
        expires           30d;
        root /opt/directories/the_site/public/;
    }



    # pass the *.php scripts to php5-fpm listening on tcp port 9000
        #
        location ~ \.php$ {

                root  /opt/directories/the_site/public/;
                index  index.php;        

        fastcgi_pass   127.0.0.1:9000;                  
                fastcgi_index  index.php;

                include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param SERVER_NAME $http_host;
                fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_ignore_client_abort on;
        }

    ## Disable viewing .htaccess & .htpassword
    location ~ /\.ht {      
        deny  all;
    }
#3

[eluser]luisfmgoncalves[/eluser]
Hello, and thanks for your response.

Actually I manage to make it work, at least part of it.

I'm having another problem now and I have no idea how to solve it.

The thing is, in the webpage I have, if a user click in a button I have there, the application should generate a file and send it to the browser, so the user can get it.
I'm not sure which is the source of the problem, because I'm just getting a 404 but I suppose is because of the headers I'm using. Is that possible?
In Apache this part is working nice with the following headers:

Code:
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/(application_type)");
header("Content-Transfer-Encoding: binary");

But with nginx this is not working.
The file is generated, because if I go the destination folder, the file is there, but this file is not sent to the browser.
Other thing, my project is in /var/www/project and the generated files are stored in /home/user/generated. Is this a problem?

In the log I'm just getting the 'No such file or directory' explain in the following link (in Error log section):
http://articles.slicehost.com/2010/8/27/...x-web-logs
So I think the problem is not related with that...

Any of you knows anything about this?

Thanks,

Luis




Theme © iAndrew 2016 - Forum software by © MyBB