好久沒用Nginx了,估計過段時間公司有些項目需要使用這個,所以決定複習下.今天晚上開始,一晚一篇.隨便說下我是在Debian Squeeze平台下.今天第1篇,從基礎開始,PHP(FastCGI).
1、 在/etc/sysctl.conf文件中加入如下內容,優化
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.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
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
/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 {
access_log /var/log/nginx/access.log;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
sendfile 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;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
9、 在/etc/nginx/sites-enabled/中刪除default
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;
root /var/www/;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
本文出自 「相濡以沫」 博客,請務必保留此出處http://onlyzq.blog.51cto.com/1228/529279
[火星人 ] Nginx總複習---1已經有278次圍觀