Thursday 08 March 2012 12:14:45 pm
Pour les personnes non anglophones, vous trouverez cet article sur http://www.pheelit.fr/HighTech/Developpement/eZ-Publish-nginx
At this time, light webserver are more and more known. For example Lighttpd (pronounced lighty ) and Nginx (Engine X). This blog post will explain how to use eZ Publish with Nginx :)
This install runs with Debian 6.0.4 and nginx 1.0.12-1
First step, we will configure apt to retrieve the latest versions of php and mysql from Dotdeb. Edit sources.list file:
vim /etc/apt/sources.list
and add:
deb http://packages.dotdeb.org squeeze all deb-src http://packages.dotdeb.org squeeze all
we need to get GPG keys:
wget http://www.dotdeb.org/dotdeb.gpg cat dotdeb.gpg | sudo apt-key add -
Finish with
apt-get update && apt-get upgrade
Really quickly
apt-get install mysql-server
and... done :)
To install php5-fpm and principals libraries, here is the command line
apt-get install php5-fpm php5-xcache php5-mcrypt php5-curl php5-mysql php5-cli
Lazy install here too.. you could add some comments above to explain how to compile each applications.
apt-get install nginx
We will be focusing on nginx and php-fpm. For mysql i let you checking some tutorials.
Contrary to what is found on the web, I do not recommend editing the file /etc/init.d/nginx unless you really know what you do.
This is /etc/nginx tree.
I let worker_processes to 1. Many website recommend changing this value to match numbers of CPU cores. So if you have a quadcore just put value: 4.
worker_connection : numbers of simultaneous connection by worker processes. Recommended value is between 512 and 2048.
keep_alive: when a visitor connect to the site, the established connection does not close shortly.This allows multiple requests passed through a single connection. It is recommended to put a value between 10 and 20 seconds.
Don't forget to reduce I/O. (please refer to access logs, error logs, open file cache, buffers and gzip compression).
You could create or modify /etc/logrotate.d/nginx if needed. Don't forget to adapt this file to your server !
/var/log/nginx/*.log {
#rotate the logfile(s) daily
daily
# adds extension like YYYYMMDD instead of simply adding a number
dateext
# If log file is missing, go on to next one without issuing an error msg
missingok
# Save logfiles for the last 10 days
rotate 10
# Old versions of log files are compressed with gzip
compress
# Postpone compression of the previous log file to the next rotation cycle
delaycompress
# Do not rotate the log if it is empty
notifempty
#after logfile is rotated and nginx.pid exists, send the USR1 signal
postrotate
[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
endscript
}
Is the directive which is specific to postrotate nginx and that matters: Once log tours/archived you throw a stop signal to Nginx to recreate log files.
Why i m talking about php files and not file ? Because php-fpm read an other php.ini file than php cli for example.
Php-fpm file is located at
/etc/php5/fpm/php.ini
And cli version
/etc/php5/cli/php.ini
Of course don't forget to increase memory_limit, max_execution_time and specify date_timezone.
The file /etc/nginx/conf.d/default.conf contains all informations about localhost domain.
We are going to create a new file named ez.conf
server {
listen 80;
server_name ez.local admin.ez.local;
root /var/www/ez;
index index.php;
if (!-f $request_filename) {
rewrite ^(.*)$ /404;
}
location ~ "^/[^/]*\.php$" {
set $script "index.php";
if ( $uri ~ "^/(.*\.php)" ) {
set $script $1;
}
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/ez/$script;
include fastcgi_params;
}
location / {
rewrite "^/var/storage/(.*)$" "/var/storage/$1" break;
rewrite "^/var/([^/]+)/storage/(.*)$" "/var/$1/storage/$2" break;
rewrite "^/var/(([^/]+/)?)cache/(texttoimage|public)/(.*)$" "/var/$1cache/$3/$4" break;
rewrite "^/design/([^/]+)/(stylesheets|images|javascript)/(.*)$" "/design/$1/$2/$3" break;
rewrite "^/share/icons/(.*)$" "/share/icons/$1" break;
rewrite "^/extension/([^/]+)/design/([^/]+)/(stylesheets|images|javascripts|javascript|flash|lib?)/(.*)$" "/extension/$1/design/$2/$3/$4" break;
rewrite "^/packages/styles/(.+)/(stylesheets|images|javascript)/([^/]+)/(.*)$" "/packages/styles/$1/$2/$3/$4" break;
rewrite "^/packages/styles/(.+)/thumbnail/(.*)$" "/packages/styles/$1/thumbnail/$2" break;
rewrite "^/favicon\.ico$" "/favicon.ico" break;
rewrite "^/robots\.txt$" "/robots.txt" break;
rewrite "^/var/cache/debug.html(.*)$" "/var/cache/debug.html$1" break;
rewrite "^/var/(([^/]+/)?)cache/public/(.*)$" "/var/$1cache/public/$3" break;
rewrite "^/var/([^/]+)/cache/debug\.html(.*)$" "/var/$1/cache/debug.html$2" break;
rewrite "content/treemenu/?$" "/index_treemenu.php" break;
rewrite "ezjscore/call/?$" "/index_ajax.php" break;
rewrite "^(.*)$" "/index.php?$1" last;
}
}
That's all for a basic virtualhost. I m using ez.local for the front office and admin.ez.local for the back office.
It's time to restart php-fpm and nginx
/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart
done :)