Anyone use CI with Nginx?

#11
[eluser]Zack Kitzmiller[/eluser]
[quote author="John Fuller" date="1220685932"][quote author="Popcorn" date="1220684667"]http://blog.skateinmars.net/post/2007/09/03/Setup-CodeIgniter-on-Nginx-server-with-fastcgi

Try this one.[/quote]

Yeah, thanks. That is how I found the thread that I linked to in my second post. I suppose I should have mentioned that. Wink

I really hate configuring web servers. Actually, I think I hate administration in general. I spend more time screwing with servers than I do actually coding.[/quote]

That is exactly the reason why we started CloudIgniter. It let's developers get back to developing.

#12
[eluser]Sire[/eluser]
[quote author="kylemac" date="1273189259"]Hey all, this may be an old post - but it comes up quite high in the google search so I thought I might mention that some of what you guys are doing can now be handled natively by nginx. Pay attention to the location block.

Code:
...
        # the try_files declaration looks for the actual file, and if !exist goes to your fallback.
        location / { try_files $uri $uri/ /index.php; }
...

Here is the nginx documentation of try_files - http://wiki.nginx.org/NginxHttpCoreModule#try_files[/quote]

This didn't work for me, but I wanted to use try_files and tested a few options. Here's what I have so far...

Code:
server {
    listen   80;
    server_name  domain;

    location / {
        root /var/www/domain;
        index index.php;
        
        if (-f $request_filename) {
            expires max;
            break;
        }

        try_files /maintenance.html $uri $uri/ @codeigniter;
    }

    location @codeigniter {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param SCRIPT_FILENAME /var/www/domain/index.php;
        include fastcgi_params;
        fastcgi_param QUERY_STRING $request_uri;
    }

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

The file /maintenance.html doesn't usually exist, but if I want to bring the site down temporarily while I work on it, all I have to do is create maintenance.html in the web root and it will be displayed to users until it is removed.

#13
[eluser]Unknown[/eluser]
[quote author="kylemac" date="1273189259"]Hey all, this may be an old post - but it comes up quite high in the google search so I thought I might mention that some of what you guys are doing can now be handled natively by nginx. Pay attention to the location block.[/quote]
I will go ahead and use the same excuse for posting here Smile

Now i wanted to do a proper config for codeigniter that did not use any Ifs whatsoever, because Ifs are evil, and worked using PATH_INFO to mix segmented URLs and querystrings.

These were made using CodeIgniter 2.0, and haven't tested them using 1.7.2, but should work
Code:
server {
    server_name     _;
    index           index.html;
    root            /var/www/;

    location / {
        try_files $uri $uri/ @codeigniter;
    }
    #Restrict access to application and system folders
    #location /system { #For 1.7.2, uncomment this and comment below to use
    location /(application|system) { #2.0, uncomment this and comment above to use - remember to edit application to your apps folder if changed
        internal;
    }

    #Cache static content
    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|swf|wav)$ {
        expires max;
    }
    location @codeigniter {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass   localhost:9000;
        fastcgi_index  index.php;

        fastcgi_split_path_info ^(/)(.*)$;
        fastcgi_param SCRIPT_FILENAME /var/www/index.php;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param DOCUMENT_ROOT /var/www/;
        fastcgi_param SERVER_NAME $http_host;
    }
}

#14
[eluser]Sulik[/eluser]
[quote author="Kenzie" date="1240193909"]Here's what I've found to work best:

Code:
server {
    listen       80;
    server_name  domain.tld www.domain.tld;
    # redirect to remove www
    if ($host = 'www.domain.tld' ) {
        rewrite  ^/(.*)$  http://domain.tld$uri  permanent;
    }
    location / {
        root /var/www/codeigniter/domain.tld/;
        index index.php index.html;
        # file doesn't exist, let CI handle it
        if (!-f $request_filename) {
            rewrite ^(.*) /index.php?$1 last;
        }
    }
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include /opt/nginx/conf/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/codeigniter/domain.tld/index.php;
     }
}

(Tested with Nginx 0.6.3, CodeIgniter 1.7.1)[/quote]


thank you! this workts like a charm! thanks

#15
[eluser]Unknown[/eluser]
im so sorry Sad cannt help you
ucweb operamini gratis hape


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.