Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4184659
  • 博文数量: 291
  • 博客积分: 8003
  • 博客等级: 大校
  • 技术积分: 4275
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-30 18:28
文章分类

全部博文(291)

文章存档

2017年(1)

2013年(47)

2012年(115)

2011年(121)

2010年(7)

分类: 系统运维

2012-02-01 21:28:04

nginx属于轻量级web服务器软件,在普通32位机器上能够支持每秒上万并发
下载nginx最新稳定版
  1. wget
1.安装php并支持pcre
  1. yum install php
  2. yum install pcre pcre-devel

2.安装start-stop-daemon
  1. wget http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
  2. tar -xzf apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
  3. cd apps/sys-utils/start-stop-daemon-IR1_9_18-2
  4. gcc start-stop-daemon.c -o start-stop-daemon
  5. cp start-stop-daemon /usr/local/sbin/
  6. cp /usr/local/sbin/start-stop-daemon /sbin/
  7. chmod +x /usr/local/sbin/start-stop-daemon
3.安装nginx-1.0.11
  1. tar -zxvf nginx-1.0.11.tar.gz
  2. cd nginx-1.0.11
  3. ./configure
  4. make;make install;

安装完的nginx在/usr/local/nginx/下,配置文件为/usr/local/nginx/nginx.conf启动nginx:
  1. /usr/local/nginx/sbin/nginx
4.生成php-fcgi服务
  1. vi /etc/init.d/php-fcgi
输入:
  1. #!/bin/bash
  2. BIND=127.0.0.1:9000
  3. USER=www-data
  4. PHP_FCGI_CHILDREN=15
  5. PHP_FCGI_MAX_REQUESTS=1000
  6. PHP_CGI=/usr/bin/php-cgi
  7. PHP_CGI_NAME=`basename $PHP_CGI`
  8. PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
  9. RETVAL=0
  10. start() {
  11. echo -n "Starting PHP FastCGI: "
  12. start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
  13. RETVAL=$?
  14. echo "$PHP_CGI_NAME."
  15. }
  16. stop() {
  17. echo -n "Stopping PHP FastCGI: "
  18. killall -q -w -u $USER $PHP_CGI
  19. RETVAL=$?
  20. echo "$PHP_CGI_NAME."
  21. }
  22. case "$1" in
  23. start)
  24. start
  25. ;;
  26. stop)
  27. stop
  28. ;;
  29. restart)
  30. stop
  31. start
  32. ;;
  33. *)
  34. echo "Usage: php-fastcgi {start|stop|restart}"
  35. exit 1
  36. ;;
  37. esac
  38. exit $RETVAL
  1. chmod +x /etc/init.d/php-fcgi
  2. chkconfig --add php-fcgi on
  3. service php-fcgi start
5.修改nginx.conf
  1. /usr/local/nginx/nginx.conf
其中worker_processes应该等于cpu的个数,下面的配置文件把web目录设置为/var/www/html/修改为:
  1. #user nobody;
  2. worker_processes 2;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 900;
  21. #gzip on;
  22. server {
  23. listen 80;
  24. server_name localhost;
  25. #charset koi8-r;
  26. #access_log logs/host.access.log main;
  27. root /var/www/html;
  28. location / {
  29. index index.php index.html index.htm;
  30. }
  31. #error_page 404 /404.html;
  32. # redirect server error pages to the static page /50x.html
  33. #
  34. error_page 500 502 503 504 /50x.html;
  35. location = /50x.html {
  36. root html;
  37. }
  38. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  39. #
  40. location ~ \.php$ {
  41. fastcgi_pass 127.0.0.1:9000;
  42. fastcgi_index index.php;
  43. fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
  44. include fastcgi_params;
  45. }
  46. }
  47. }
重新加载配置文件
  1. /usr/local/nginx/sbin/nginx -s reload
6.测试
  1. echo "" > /var/www/html/test.php
  2. wget
7.添加nginx服务
  1. useradd nginx
  2. vi /etc/init.d/nginx
  1. #!/bin/bash
  2. # nginx Startup script for the Nginx HTTP Server
  3. #
  4. # chkconfig: - 85 15
  5. # description: Nginx is a high-performance web and proxy server.
  6. # It has a lot of features, but it's not for everyone.
  7. # processname: nginx
  8. # pidfile: /var/run/nginx.pid
  9. # config: /usr/local/nginx/conf/nginx.conf
  10. nginxd=/usr/local/nginx/sbin/nginx
  11. nginx_config=/usr/local/nginx/conf/nginx.conf
  12. nginx_pid=/usr/local/nginx/logs/nginx.pid
  13. RETVAL=0
  14. prog="nginx"
  15. # Source function library.
  16. . /etc/rc.d/init.d/functions
  17. # Source networking configuration.
  18. . /etc/sysconfig/network
  19. # Check that networking is up.
  20. [ ${NETWORKING} = "no" ] && exit 0
  21. [ -x $nginxd ] || exit 0
  22. # Start nginx daemons functions.
  23. start() {
  24. if [ -e $nginx_pid ];then
  25. echo "nginx already running...."
  26. exit 1
  27. fi
  28. echo -n $"Starting $prog: "
  29. daemon $nginxd -c ${nginx_config}
  30. RETVAL=$?
  31. echo
  32. [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
  33. return $RETVAL
  34. }
  35. # Stop nginx daemons functions.
  36. stop() {
  37. echo -n $"Stopping $prog: "
  38. killproc $nginxd
  39. RETVAL=$?
  40. echo
  41. [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
  42. }
  43. # reload nginx service functions.
  44. reload() {
  45. echo -n $"Reloading $prog: "
  46. $nginxd -s reload
  47. #if your nginx version is below 0.8, please use this command: "kill -HUP `cat ${nginx_pid}`"
  48. RETVAL=$?
  49. echo
  50. }
  51. # See how we were called.
  52. case "$1" in
  53. start)
  54. start
  55. ;;
  56. stop)
  57. stop
  58. ;;
  59. reload)
  60. reload
  61. ;;
  62. restart)
  63. stop
  64. start
  65. ;;
  66. status)
  67. status $prog
  68. RETVAL=$?
  69. ;;
  70. *)
  71. echo $"Usage: $prog {start|stop|restart|reload|status|help}"
  72. exit 1
  73. esac
  74. exit $RETVAL
自动启动服务:
  1. chkconfig --add nginx on
end
阅读(1903) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

yjyzfw2012-02-06 00:49:23

好文,谢谢分享了