好久没用Nginx了,估计过段时间公司有些项目需要使用这个,所以决定复习下。今天晚上开始,一晚一篇。随便说下我是在Debian Squeeze平台下。今天第1篇,从基础开始,PHP(FastCGI)。
1、 在/etc/sysctl.conf文件中加入如下内容,优化Linux内核参数。
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.ip_local_port_range = 1024 65535
2、 使用如下命令使/etc/sysctl.conf文件配置生效。
root@srv76:~# sysctl -p
3、 使用如下命令安装Nginx。
root@srv76:~# apt-get install nginx
4、 使用如下命令安装PHP。
root@srv76:~# apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl spawn-fcgi
5、 在/etc/php5/cgi/php.ini文件中如下内容的注释取消。
cgi.fix_pathinfo = 1
6、 执行如下命令启动FastCGI。
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
7、 将上一句加入/etc/rc.local文件中,使用其每次在开机的时间都会执行。
8、 修改/etc/nginx/nginx.conf文件中如下内容。
user www-data;
worker_processes 10;
error_log /var/log/nginx/error.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
sendfile on;
tcp_nopush on;
keepalive_timeout 50;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain text/css application/x-javascript application/xml;
gzip_vary on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
9、 在/etc/nginx/sites-enabled/中删除default文件并建立名为wiki的文件后如下内容。
server {
listen 80;
server_name _;
access_log /var/log/nginx/localhost.access.log;
location / {
root /web/wiki/;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /web/wiki$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}