Fritz Thomas

17 Jul, 2010

How To use FLOW3 with NGINX – working server configuration

Posted by: Fritz Thomas In: Linux|PHP

I installed the default nginx package available in Ubuntu 10.04 server. For PHP-5.3.2 you have to use the cgi version, of course. But enough of the words.

It is really really simple, so i just post the config files. The only “trickier” part was to convert the Apache Rewrite Rules from the FLOW3 distribution. After this you can completly delete the .htaccess file.

It should be self-explanatory:


/etc/nginx/sites/flow3.conf:

 
server {
        listen          80; 
        server_name     flow3.local *.flow3.local;
        root            /var/www/test/flow3/Web;
        autoindex       off; 
 
        access_log      /var/www/test/logs/access.log combined;
        error_log       /var/www/test/logs/error.log info;
 
        location ~ "^/_Resources/Persistent/" {
                rewrite "^(_Resources/Persistent/.{40})/.+(\..+)" /$1$2 break;
        }   
 
        location ~ "^/_Resources/" {
                access_log off;
                log_not_found off;
                expires max;
                break;
        }   
 
        location / { 
                rewrite ".*" /index.php last;
        }   
 
        location = /index.php {
                #fastcgi_param   FLOW3_CONTEXT          Development;
                fastcgi_param   FLOW3_CONTEXT           Production;
                fastcgi_param   FLOW3_REWRITEURLS       1;  
                fastcgi_intercept_errors on; 
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include includes/fastcgi_params;
 
                # "Upstream" defined in nginx.conf
                fastcgi_pass    php-5.3.2; 
        }   
}

/etc/nginx/includes/fastcgi_params:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
 
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
 
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
 
#the two lines below are possible now because of the fastcgi_split_path_info function
fastcgi_param  PATH_INFO          $fastcgi_path_info;
fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;
 
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
 
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
 
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

/etc/nginx/nginx.conf:

user                            www-data www-data;
worker_processes                1;  
 
error_log                       /var/log/nginx/error.log;
pid                             /var/run/nginx.pid;
 
events {
        accept_mutex            on; 
        worker_connections      512;
        # use [ kqueue | rtsig | epoll | /dev/poll | select | poll ] ;
        use                     epoll;
        multi_accept            on; 
}
 
http {
        include                 mime.types;
        default_type            application/octet-stream;
 
        access_log              /var/log/nginx/access.log;
 
        sendfile                on; 
        tcp_nopush              on; 
        tcp_nodelay             on; 
 
        keepalive_timeout       75 20; 
 
        gzip                    on; 
        gzip_comp_level         1;  
        gzip_min_length         1100;
        gzip_buffers            4 8k; 
        gzip_types              text/plain text/css application/x-javascript text/xml application/xml text/javascript application/json application/javascript text/json application/x-json;
        upstream php-5.3.2 {
            server unix:/var/run/php/5.3.2/fpm.sock;
        }
        include                 sites/*.conf;
}

On a next Blog Post i will show how to compile php-5.3.x as php-fpm SAPI and how to configure and use it.

  • Digg
  • del.icio.us
  • DZone
  • MisterWong
  • Reddit
  • Slashdot
  • Technorati
  • Google Bookmarks
  • Facebook
  • Twitter
  • Yahoo! Bookmarks
  • Yigg
  • LinkedIn
  • MySpace
  • PDF
  • RSS

2 Responses to "How To use FLOW3 with NGINX – working server configuration"

1 | MySchizoBuddy

July 17th, 2010 at 11:28 pm

Avatar

Can you add this to flow3 issue tracker so it can be part of the documentation.

2 | zjhong

July 18th, 2010 at 5:25 am

Avatar

very nice!

Comment Form



Latest Tweets