原文链接:http://bbs.linuxpk.com/thread-11845-1-1.html
Nginx介绍:
Nginx发音为[engine x],是由俄罗斯人Igor Sysoev建立的项目,基于BSD许可。
据说他当初是F5的成员之一,英文主页:http://nginx.net。俄罗斯的一些大网站已经使用它超过两年多了, 一直表现不凡,相信想了解nginx的朋友都读过阿叶大哥的利用nginx实现负载均衡的文章相关链接见(六)。
测试环境:红动中国(redocn)提供运营服务器环境.
关于红动服务环境:
红动中国在早期利用apache环境,再加上一些优化的工作,一直是相对很重定,但是最近由于网站发展,访问量越来越大,在线人数一多经常出现,负载过高,性能急剧下降,经过双木站长的同意,考虑是否能利用nginx来代替apache,经过长时间的观察目前nginx工作很稳定,系统也不会再说现高负载的状况,占用内存也很低,访问速率从用户体验来看明显有提升.
关于红动中国:
红动中国(redocn)论坛经过近1年的快速发展,目前日均页面访问量超过100万,位居全球设计论坛(中文)第1位,是国内最具影响力的设计论坛之一。目前论坛拥有近20万会员,包括众多设计界领军人物在内的行业中坚力量、相关艺术院校师生以及部分设计爱好者等。
迁移目标:实现网站论坛静态化,防盗链,下载并发数和速率限制,实现原站apache所具有的所有功能,将原apache环境下的站点全部迁移到Nginx
一.PHP(Fastcgi)编译安装
[root@att php-5.2.4]# cat in.sh
|
class=codetop>CODE:
class=codemain>./configure \ "--prefix=/usr/local/php-fcgi" \ "--enable-fastcgi" \ "--enable-discard-path" \ "--enable-force-cgi-redirect" \ "--with-config-file-path=/usr/local/php-fcgi/etc" \ "--enable-zend-multibyte" \ "--with-mysql=/usr/local/mysql" \ "--with-libxml-dir=/usr/local/libxml2" \ "--with-gd=/usr/local/gd2" \ "--with-jpeg-dir" \ "--with-png-dir" \ "--with-bz2" \ "--with-freetype-dir" \ "--with-iconv-dir" \ "--with-zlib-dir " \ "--with-openssl=/usr/local/openssl" \ "--with-mcrypt=/usr/local/libmcrypt" \ "--enable-sysvsem" \ "--enable-inline-optimization" \ "--enable-soap" \ "--enable-gd-native-ttf" \ "--enable-ftp" \ "--enable-mbstring" \ "--enable-exif" \ "--disable-debug" \ "--disable-ipv6" make make install cp php.ini-dist /usr/local/php-fcgi/etc/php.ini |
注:关于如何安装gd库,mysql的编译安装,本文将不介绍,本文重点在于介绍nginx的安装与配置,如想了解其它相关的问题可以到
LinuxPk去找相关的贴子(http://bbs.linuxpk.com)
二.Nginx编译安装
1.创建nginx运行用户和虚拟主机目录
|
class=codetop>CODE:
class=codemain>groupadd www -g 48 useradd -u 48 -g www www mkdir -p /data/www/wwwroot chown -R www:www /data/www/wwwroot |
2.安装lighttpd中附带的spawn-fcgi,用来启动php-cgi
先编译安装lighttpd产生spawn-fcgi二进制文件.
|
class=codetop>CODE:
class=codemain>cd /usr/local/src/lighttpd-1.4.18 cp src/spawn-fcgi /usr/local/php-fcgi/bin/ |
启动php-cgi进程,监听127.0.0.1的8085端口,进程数为250(如果服务器内存小于3GB,可以只开启25个进程),用户为www:
/usr/local/php-fcgi/bin/spawn-fcgi -a 127.0.0.1 -p 8085 -C 250 -u www -f /usr/local/php-fcgi/bin/php-cgi
3.nginx的安装与配置
安装Nginx所需的pcre库:
http://ftp.dk.debian.org/exim/pcre/pcre-7.3.tar.gz
|
class=codetop>CODE:
class=codemain>tar zxvf pcre-7.2.tar.gz cd pcre-7.2/ ./configure make && make install cd ../ http://sysoev.ru/nginx/nginx-0.5.32.tar.gz tar zxvf nginx-0.5.32.tar.gz cd nginx-0.5.32 ./configure --user=www --group=www --prefix=/usr/local/nginx/ --with-http_stub_status_module --with- openssl=/usr/local/openssl make && make install |
此模块非核心模块,需要在编译的时候手动添加编译参数 --with-http_stub_status_module
配置nginx
三.Nginx主配置文件及PHP支持.
1.nginx.conf 主配置文件的配置
#cd /usr/local/nginx/conf/
#cp nginx.conf nginx.conf.cao
#cat /dev/null > nginx.conf
#vi nginx.conf //主配置文件
|
class=codetop>CODE:
class=codemain>user www www; worker_processes 10; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid /var/run/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 51200; events { use epoll; #maxclient = worker_processes * worker_connections / cpu_number worker_connections 51200; } http { include conf/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; #access_log /data/www/logs/access.log main; #sendfile on; tcp_nopush on; tcp_nodelay off; keepalive_timeout 60; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 4 2k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; client_max_body_size 10m; client_body_buffer_size 256k; client_body_temp_path /dev/shm/client_body_temp; proxy_temp_path /usr/local/nginx/proxy_temp; fastcgi_temp_path /usr/local/nginx/fastcgi_temp; #gzip gzip on; gzip_http_version 1.0; gzip_comp_level 2; gzip_proxied any; gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; gzip_min_length 1100; gzip_buffers 4 8k; # The following includes are specified for virtual hosts //以下是加载虚拟主机配置. #www.redocn.com include conf/vhosts/www_redocn_com.conf; #bbs.redocn.com include conf/vhosts/bbs_redocn_com.conf; #blog.redocn.com include conf/vhosts/blog_redocn_com.conf; #down.redocn.com include conf/vhosts/down_redocn_com.conf; } |

添加到雅虎收藏