CentOS 6.2企业级LNMP环境搭建(5)

 

 

首页服务器应用

背景:

阅读新闻

CentOS 6.2企业级LNMP环境搭建

[日期:2012-04-23]   来源:Linux社区  作者:gaby   [字体:]  

4,安装nginx

tar xf pcre-8.20.tar.bz2    
cd pcre-8.20
./configure    
make && make install
cd ../
tar xf nginx-1.1.9.tar.gz    
cd nginx-1.1.9
./configure \
     --prefix=/usr \
     --sbin-path=/usr/sbin/nginx \
     --conf-path=/etc/nginx/nginx.conf \
     --error-log-path=/var/log/nginx/error.log \
     --http-log-path=/var/log/nginx/access.log \
     --pid-path=/var/run/nginx/nginx.pid    \
     --lock-path=/var/lock/nginx.lock \
     --user=www \
     --group=www \
     --with-http_ssl_module \
     --with-http_flv_module \
     --with-http_stub_status_module \
     --with-http_gzip_static_module \
     --http-client-body-temp-path=/var/usr/local/src/nginx/client/ \
     --http-proxy-temp-path=/var/usr/local/src/nginx/proxy/ \
     --http-fastcgi-temp-path=/var/usr/local/src/nginx/fcgi/ \
     --with-pcre \
make && make install
cd ..

 

修改nginx配置文件
 mv  /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
vim /etc/nginx/nginx.conf  添加如下代码

user  www www;
worker_processes  4;

#error_log  /var/log/nginx、error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
  use epoll;
  worker_connections 65535;
}

http
{
  include       mime.types;
  default_type  application/octet-stream;
  #charset  gb2312;
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;

  sendfile on;
  tcp_nopush     on;

  keepalive_timeout 60;

  tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;

  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-Javascript text/css application/xml;
  gzip_vary on;

  #limit_zone  crawler  $binary_remote_addr  10m;

  server
  {
    listen       80;
    server_name ;
    index index.html index.htm index.php;
    root  html;

    #limit_conn   crawler  20;   

    location ~ .*\.(php|php5)?$
    {
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fcgi.conf;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
      expires      1h;
    }

    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
    access_log  /var/log/nginx/access.log   access;
 }
}

为nginx提供sv启动脚本
vim /etc/init.d/nginx

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:     - 85 15    
# description:    Nginx is an HTTP(S) server, HTTP(S) reverse \
#                             proxy and IMAP/POP3 proxy server
# processname: nginx
# config:            /etc/nginx/nginx.conf
# config:            /etc/sysconfig/nginx
# pidfile:         /var/run/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

make_dirs() {
     # make required directories
     user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
     options=`$nginx -V 2>&1 | grep 'configure arguments:'`
     for opt in $options; do
             if [ `echo $opt | grep '.*-temp-path'` ]; then
                     value=`echo $opt | cut -d "=" -f 2`
                     if [ ! -d "$value" ]; then
                             # echo "creating" $value
                             mkdir -p $value && chown -R $user $value
                     fi
             fi
     done
}

start() {
        [ -x $nginx ] || exit 5
        [ -f $NGINX_CONF_FILE ] || exit 6
        make_dirs
        echo -n $"Starting $prog: "
        daemon $nginx -c $NGINX_CONF_FILE
        retval=$?
        echo
        [ $retval -eq 0 ] && touch $lockfile
        return $retval
}

stop() {
        echo -n $"Stopping $prog: "
        killproc $prog -QUIT
        retval=$?
        echo
        [ $retval -eq 0 ] && rm -f $lockfile
        return $retval
}

restart() {
        configtest || return $?
        stop
        sleep 1
        start
}

reload() {
        configtest || return $?
        echo -n $"Reloading $prog: "
        killproc $nginx -HUP
        RETVAL=$?
        echo
}

force_reload() {
        restart
}

configtest() {
    $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
        status $prog
}

rh_status_q() {
        rh_status >/dev/null 2>&1
}

case "$1" in
        start)
                rh_status_q && exit 0
                $1
                ;;
        stop)
                rh_status_q || exit 0
                $1
                ;;
        restart|configtest)
                $1
                ;;
        reload)
                rh_status_q || exit 7
                $1
                ;;
        force-reload)
                force_reload
                ;;
        status)
                rh_status
                ;;
        condrestart|try-restart)
                rh_status_q || exit 0
                        ;;
        *)
                echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
                exit 2
esac

chkconfig --add nginx
测试如下
[root@localhost ~]# service nginx start
Starting nginx:                                            [  OK  ]
[root@localhost ~]# service nginx restart
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[root@localhost ~]#

CentOS 6.2企业级LNMP环境搭建

 

Dnode:基于Node.js给浏览器提供异步远程方法调用

CentOS下HAProxy配置步骤

相关资讯       LNMP  CentOS安装 

   

本文评论   查看全部评论 (0)


评论声明

尊重网上道德,遵守中华人民共和国的各项有关法律法规

承担一切因您的行为而直接或间接导致的民事或刑事法律责任

本站管理人员有权保留或删除其管辖留言中的任意内容

本站有权在网站内转载或引用您的评论

参与本评论即表明您已经阅读并接受上述条款

 

 

 

最新资讯

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/cda7205e809647dcb90cad78f57207a0.html