Code can be found at: bitbucket.org/javiyt/workshop_nginx
Install nginx and check the basic configuration parameters
sudo aptitude install nginx
user www-data; worker_processes 4; pid /run/nginx.pid; events { worker_connections 768; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
sudo aptitude install php5-fpm
;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;
;include=/etc/php5/fpm/*.conf
;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;
[global]
pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log
syslog.facility = daemon
log_level = debug
process.max = 128
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;
include=/etc/php5/fpm/pool.d/*.conf
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9001
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.process_idle_timeout = 10s;
pm.max_requests = 500
pm.status_path = /fpm-status
access.log = /var/log/php-fpm/$pool.access.log
slowlog = /var/log/php-fpm/$pool.log.slow
request_slowlog_timeout = 10s;
chroot = /vagrant/www/
chdir = /
catch_workers_output = yes
security.limit_extensions = .php
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
env[PHP_ENVIRONMENT] = 'development'
php_flag[display_errors] = off
php_admin_value[memory_limit] = 32M
php_admin_value[error_log] = /var/log/php-fpm/$pool.error.log
/etc/init.d/php5-fpm restart
mkdir /var/log/php-fpm/
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /vagrant/www;
index index.html index.htm index.php;
error_page 404 /404.html;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location /test {
alias /vagrant/www/aliastest/;
}
location ~ php/.*\.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9001;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
http://localhost:8080/php/info.php
location ~ ^/fpm-status$ {
access_log off;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9001;
}
http://localhost:8080/fpm-status
upstream cluster_php {
server 127.0.0.1:9001;
server 127.0.0.1:9002;
}
location ~ php/.*\.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass cluster_php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
http://localhost:8080/php/info.php
wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -
echo deb http://dl.hhvm.com/ubuntu trusty main | sudo tee /etc/apt/sources.list.d/hhvm.list
sudo apt-get update
sudo apt-get -y install hhvm
sudo /usr/share/hhvm/install_fastcgi.sh
sudo /etc/init.d/hhvm restart
location ~ hhvm/.*\.(hh|php)$ {
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
sudo /usr/share/hhvm/install_fastcgi.sh
sudo /etc/init.d/hhvm restart
sudo /etc/init.d/nginx restart
location ~ img/(?<width>[0-9]+)/(?<height>[0-9]+)/(?<filename>.*) {
alias /vagrant/www/$filename;
image_filter resize $width $height;
image_filter_jpeg_quality 75;
}