你好,游客 登录 注册 搜索
背景:
阅读新闻

LNAMP第二版(Nginx 1.2.0+Apache 2.4.2+PHP 5.4)

[日期:2012-05-09] 来源:Linux社区  作者:kerry [字体:大 中 小]
#============= Install Nginx ===================#
cd /opt
tar -zxvf nginx-1.2.0.tar.gz
cd nginx-1.2.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-pcre=/opt/pcre-8.30 --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-google_perftools_module
make;make install

cd ../

#添加nginx启动脚本

  1. cat >> /etc/init.d/nginx <<EOF 
  2. #! /bin/sh  
  3. ulimit -n 65535  
  4. # Description: Startup script for nginx  
  5. # chkconfig: 2345 55 25  
  6.  
  7. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin  
  8. DESC="nginx daemon" 
  9. NAME=nginx 
  10. DAEMON=/usr/local/nginx/sbin/$NAME  
  11. CONFIGFILE=/usr/local/nginx/conf/nginx.conf  
  12. PIDFILE=/usr/local/nginx/logs/$NAME.pid  
  13. SCRIPTNAME=/etc/init.d/$NAME  
  14.  
  15. set -e  
  16. [ -x "$DAEMON" ] || exit 0  
  17.  
  18. do_start() {  
  19.  $DAEMON -c $CONFIGFILE || echo -n "nginx already running"  
  20. }  
  21.  
  22. do_stop() {  
  23.  kill -QUIT `cat $PIDFILE` || echo -n "nginx not running"  
  24. }  
  25.  
  26. do_reload() {  
  27.  kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"  
  28. }  
  29.  
  30. case "$1" in  
  31.  start)  
  32.  echo -n "Starting $DESC: $NAME"  
  33.  do_start  
  34.  echo "."  
  35.  /etc/init.d/httpd start  
  36.  ;;  
  37.  stop)  
  38.  echo -n "Stopping $DESC: $NAME"  
  39.  do_stop  
  40.  echo "."  
  41.  /etc/init.d/httpd stop  
  42.  ;;  
  43.  reload)  
  44.  echo -n "Reloading $DESC configuration..."  
  45.  do_reload  
  46.  echo "."  
  47.  /etc/init.d/httpd restart  
  48.  ;;  
  49.  restart)  
  50.  echo -n "Restarting $DESC: $NAME"  
  51.  do_stop  
  52.  sleep 1  
  53.  do_start  
  54.  echo "."  
  55.  /etc/init.d/httpd restart  
  56.  ;;  
  57.  *)  
  58.  echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2  
  59.  exit 3  
  60.  ;;  
  61. esac  
  62.  
  63. exit 0  
  64. EOF 

#添加nginx配置文件
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

  1. cat >> /usr/local/nginx/conf/nginx.conf <<EOF 
  2. user  www www;     
  3. worker_processes 8;   
  4. error_log  /usr/local/nginx/logs/nginx_error.log  crit;   
  5. pid        /usr/local/nginx/logs/nginx.pid;   
  6. #使用Tcmalloc优化nginx性能  
  7. google_perftools_profiles /var/tmp/tcmalloc;  
  8. #Specifies the value for maximum file descriptors that can be opened by this process.   
  9. worker_rlimit_nofile 65535;   
  10. #工作模式及连接数上限   
  11. events   
  12. {    
  13.  use epoll;    
  14.  worker_connections 65535;   
  15. }   
  16. #设定http服务器,利用它的反向代理功能提供负载均衡支持   
  17. http   
  18. {     
  19.   #设定mime类型     
  20.   include       mime.types;     
  21.   default_type  application/octet-stream;       
  22.   #charset  gb2312;    
  23.   #设定请求缓冲        
  24.   server_names_hash_bucket_size 128;     
  25.   client_header_buffer_size 32k;    
  26.   large_client_header_buffers 4 32k;    
  27.   client_max_body_size 30m;   
  28.   sendfile on;    
  29.   tcp_nopush     on;     
  30.   keepalive_timeout 60;   
  31.   tcp_nodelay on;   
  32.   server_tokens off;  
  33.   client_body_buffer_size 512k;   
  34.   proxy_connect_timeout   5;   
  35.   proxy_send_timeout      60;   
  36.   proxy_read_timeout      5;   
  37.   proxy_buffer_size       16k;   
  38.   proxy_buffers           4 64k;   
  39.   proxy_busy_buffers_size 128k;   
  40.   proxy_temp_file_write_size 128k;   
  41.   #  fastcgi_connect_timeout 300;   
  42.   #  fastcgi_send_timeout 300;   
  43.   #  fastcgi_read_timeout 300;   
  44.   #  fastcgi_buffer_size 64k;   
  45.   #  fastcgi_buffers 4 64k;   
  46.   #  fastcgi_busy_buffers_size 128k;   
  47.   #  fastcgi_temp_file_write_size 128k;     
  48.   gzip on;   
  49.   gzip_min_length  1k;   
  50.   gzip_buffers     4 16k;   
  51.   gzip_http_version 1.1;   
  52.   gzip_comp_level 2;   
  53.   gzip_types       text/plain application/x-javascript text/css application/xml;   
  54.   gzip_vary on;   
  55.     
  56.   #limit_zone  crawler  $binary_remote_addr  10m;   
  57.   #定义访问日志的写入格式  
  58.   log_format  wwwlog  '$remote_addr - $remote_user [$time_local] "$request" '                
  59.  '$status $body_bytes_sent "$http_referer" '               
  60.  '"$http_user_agent" $http_x_forwarded_for';   
  61.   log_format  bbslog  '$remote_addr - $remote_user [$time_local] "$request" '                
  62.  '$status $body_bytes_sent "$http_referer" '               
  63.  '"$http_user_agent" $http_x_forwarded_for';  
  64.  
  65.   ###禁止通过ip访问站点    
  66.    server{           
  67.  server_name _;           
  68.  return 404;           
  69.   }    
  70.   server  
  71.   {       
  72.  listen       80;      
  73.  server_name  www.linuxidc.com;      
  74.  index index.html index.htm index.php;#设定访问的默认首页地址       
  75.  root  /data/www/linuxidc;#设定网站的资源存放路径        
  76.  #limit_conn   crawler  20;    
  77.  if (-d $request_filename)  
  78.  {  
  79.   rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;  
  80.  }  
  81.  #所有jsp的页面均交由tomcat处理  
  82.  location ~ \.(php)?$ {  
  83.   proxy_set_header  Host $host;    
  84.   proxy_set_header  X-Real-IP  $remote_addr;  
  85.   proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
  86.   proxy_pass http://127.0.0.1:81;#转向tomcat处理         
  87.  }              
  88.  location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ #设定访问静态文件直接读取不经过apache       
  89.  {         
  90.   expires      30d;       
  91.  }        
  92.  location ~ .*\.(js|css)?$       
  93.  {         
  94.   expires      1h;       
  95.  }                 
  96.  access_log  /data/logs/linuxidc/linuxidc_nginx.log wwwlog;#设定访问日志的存放路径    
  97.    }   
  98.   server  
  99.   {       
  100.  listen       80;      
  101.  server_name  www.king.com;      
  102.  index index.html index.htm index.php;#设定访问的默认首页地址       
  103.  root  /data/www/king;#设定网站的资源存放路径        
  104.  #limit_conn   crawler  20;    
  105.  if (-d $request_filename)  
  106.  {  
  107.   rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;  
  108.  }  
  109.  #所有jsp的页面均交由tomcat处理  
  110.  location ~ \.(php)?$ {         
  111.   proxy_set_header  Host $host;    
  112.                 proxy_set_header  X-Real-IP  $remote_addr;  
  113.   proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
  114.   proxy_pass http://127.0.0.1:81;#转向tomcat处理         
  115.  }              
  116.  location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ #设定访问静态文件直接读取不经过apache       
  117.  {         
  118.   expires      30d;       
  119.  }        
  120.  location ~ .*\.(js|css)?$       
  121.  {         
  122.   expires      1h;       
  123.  }          
  124.  access_log  /data/logs/king/king_nginx.log bbslog;#设定访问日志的存放路径    
  125.    }   
  126.    server  
  127.    {  
  128.  listen  80;  
  129.  server_name  status.www.linuxidc.com;  
  130.  location / {  
  131.  stub_status on;  
  132.  access_log   off;  
  133.  }  
  134.    }  
  135. }   
  136. EOF 

#将nginx添加到启动服务中
chmod 700 /etc/init.d/nginx
/etc/init.d/nginx start
/sbin/chkconfig --add nginx
/sbin/chkconfig --level 2345 nginx on

linux
相关资讯       LNAMP 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款