[Ubuntu note.] Nginx+PHP5-FPM+APC 筆記

Update: 如果有使用 memcached 來整合 session,請不要安裝 php5-suhosin,或是去研究一下 suhosin 的設定 因為我是懶人,所以作筆記也是很合理的!

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:brianmercer/php
sudo apt-get update
sudo apt-get install nginx
sudo apt-get install php5-common php5-cgi php5-cli php5-fpm php5-mysql php5-curl php5-mcrypt php5-suhosin
sudo apt-get install php-pear php-apc

首先是 sites-available 設定檔。

server {

    listen 80 default;
    server_name  localhost;
    charset utf-8;
    access_log  /var/log/nginx/localhost.access.log combined;

    location / {
        root   /var/www/;
        index  index.html index.php;
    }
    location ~ .*\.php$ {
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /var/www$fastcgi_script_name;
        include        fastcgi_params;
    }
    location ~ /\.ht {
        deny  all;
    }
    location ~ \.(gif|jpg|jpeg|png|bmp|ico|rar|css|js|zip|tar|gz|java|jar|txt|flv|swf|mid|doc|ppt|xls|pdf|txt|mp3|wma)$ {
        access_log off;
        expires 10d;
    }
}

記得 PHP5-FPM 改成 socket 的模式。

Nginx 的設定檔,請不要照抄。

user www-data;
worker_processes  4;
pid /var/run/nginx.pid;

events {
    use epoll;
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    types_hash_max_size 2048;
    keepalive_timeout 30;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_disable "MSIE [1-6].(?!.*SV1)";
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    fastcgi_intercept_errors on;
    fastcgi_ignore_client_abort on;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 60;
    fastcgi_read_timeout 120;
    fastcgi_buffer_size 32k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
Hina Chen
偏執與強迫症的患者,算不上是無可救藥,只是我已經遇上我的良醫了。
Taipei