lnmp 원 키 설치 - nginx
  
  
  
  
   
   
   
   - #!/bin/bash  
- #version 1.0  
- #date    2013-05-04  
- #author  yangcan  
- #mail    [email protected]  
- _work_path=`pwd`  
- # user define  
- _nginx_path=/usr/local/nginx  
- _nginx_user=ycan  
- _nginx_group=ycan  
- [ id $_nginx_user >/dev/null 2>&1 ] || useradd -r -s /sbin/nologin $_nginx_user  
- mkdir /var/tmp/tcmalloc/ && chmod -R  777 /var/tmp/tcmalloc/  
- mkdir /var/tmp/nginx_body  
- mkdir /var/tmp/proxy_temp  
- mkdir /var/tmp/fastcgi_temp  
- mkdir /var/tmp/uwsgi_temp  
- mkdir /var/tmp/scgi_temp  
- chown -R $_nginx_user:$_nginx_group /var/tmp/*  
- _check_stats() {  
-         if [ $? == 0 ];then 
-                 echo "*************************************" >>$_work_path/install.log  
-                 echo "$1 : at $(date +'%F %T') install OK "  >>$_work_path/install.log  
- else 
-                 echo "*************************************" >>$_work_path/install.log  
-                 echo "$1 : at $(date +'%F %T') install               <<FAIL>> "  >>$_work_path/install.log  
-         fi  
- }  
- _check_file() {  
- ( yum grouplist|grep -B 100 "Available Groups:"|grep "Development Libraries" ) || yum groupinstall "Development Libraries" 
- ( yum grouplist|grep -B 100 "Available Groups:"|grep "Development Tools" ) || yum groupinstall "Development Tools" 
- yum -y install perl-devel perl-ExtUtils-Embed  
- [ -s libunwind-1.1.tar.gz ] || wget -c http://ftp.twaren.net/Unix/NonGNU//libunwind/libunwind-1.1.tar.gz  
- [ -s zlib-1.2.7.tar.gz ] || wget -c http://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.7/zlib-1.2.7.tar.gz  
- [ -s pcre-8.32.tar.gz ] || wget -c http://nchc.dl.sourceforge.net/project/pcre/pcre/8.32/pcre-8.32.tar.gz  
- [ -s nginx-1.2.8.tar.gz ] || wget -c http://nginx.org/download/nginx-1.2.8.tar.gz  
- [ -s gperftools-2.0.tar.gz ] || wget -c https://gperftools.googlecode.com/files/gperftools-2.0.tar.gz  
- }  
- _install_nginx_depth() {  
- cd $_work_path  
- tar zxf pcre-8.32.tar.gz   
- cd pcre-8.32  
- ./configure  
- make && make install  
- _check_stats pcre-8.32  
- /sbin/ldconfig  
- # 64bit need,but 32bits not need.  
- cd $_work_path  
- tar zxf libunwind-1.1.tar.gz   
- cd libunwind-1.1  
- ./configure --enable-shared 
- make && make install  
- _check_stats libunwind-1.1  
- cd $_work_path  
- tar zxf  gperftools-2.0.tar.gz   
- cd gperftools-2.0   
- ./configure --enable-shared --enable-frame-pointers 
- make && make install  
- _check_stats gperftools-2.0  
- /sbin/ldconfig  
- }  
- _install_nginx() {  
- cd $_work_path  
- tar zxf nginx-1.2.8.tar.gz     
- cd nginx-1.2.8  
- ./configure --prefix=$_nginx_path --user=$_nginx_user --group=$_nginx_group \ 
- --with-pcre \ 
- --with-http_ssl_module \ 
- --with-http_realip_module \ 
- --with-http_sub_module  \ 
- --with-http_flv_module  \ 
- --with-http_gzip_static_module  \ 
- --with-http_stub_status_module  \ 
- --with-http_perl_module \ 
- --with-google_perftools_module \ 
- --http-client-body-temp-path=/var/tmp/nginx_body \ 
- --http-proxy-temp-path=/var/tmp/proxy_temp \ 
- --http-fastcgi-temp-path=/var/tmp/fastcgi_temp \ 
- --http-uwsgi-temp-path=/var/tmp/uwsgi_temp \ 
- --http-scgi-temp-path=/var/tmp/scgi_temp \ 
- --without-mail_pop3_module \ 
- --without-mail_imap_module \ 
- --without-mail_smtp_module \ 
- --pid-path=/var/run/nginx.pid 
- [ $? == 0 ] && make   
- [ $? == 0 ] && make install  
- _check_stats nginx  
- }  
- if [ `id -u` -ne 0 ];then 
-     echo "install nginx need root" 
-     exit 1  
- else 
-     _check_file  
-     _install_nginx_depth  
-     _install_nginx  
-     [ $? -eq 0 ] && echo " $(date +"%F %T")  @@@@@@@ nginx COMPLETE  @@@@@@ " >> $_work_path/install.log  
-     sleep 5  
- fi  
2. nginx. conf 설정
  
  
  
  
   
   
   
   - user ycan ycan;  
- worker_processes 8;  
- worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;  
- error_log  /home/logs/error.log notice;  
- #error_log  /usr/local/nginx/logs/error.log  notice;  
- #error_log  /usr/local/nginx/logs/error.log  info;  
- #pid        logs/nginx.pid;  
- worker_rlimit_nofile 65535;  
- events {  
-     use epoll;  
-     worker_connections 30000;  
- }  
- http {  
-     include       mime.types;  
-     default_type  application/octet-stream;  
-     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  logs/access.log  main;  
-     sendfile            on;  
-     tcp_nopush          on;  
-     tcp_nodelay         on;  
-     keepalive_timeout   60;  
-     #ip_hash;  
-     ignore_invalid_headers   on;  
-     recursive_error_pages    on;  
-     server_name_in_redirect off;  
-     server_tokens           off;  
-     gzip on;  
-     gzip_comp_level     9;  
-     gzip_min_length     1100;  
-     gzip_buffers        4 8k;  
-     gzip_http_version   1.1;  
-     gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;  
-     server_names_hash_bucket_size   256;  
-     client_header_buffer_size       16K;  
-     large_client_header_buffers     4 64k;  
-     client_max_body_size            50m;  
-     client_body_buffer_size         256k;  
-     client_header_timeout           5m;  
-     client_body_timeout             3m;  
-     send_timeout                    5m;  
-     open_file_cache max=204800 inactive=20s;  
-     open_file_cache_min_uses 1;  
-     open_file_cache_valid 30s;  
-     fastcgi_intercept_errors on;  
-     server {  
-         listen 80 default;  
-         server_name _;  
- return 444;  
-     }  
-     server  
-     {  
-         listen          80;  
-         server_name     www.ycan.com;  
- indexindex.html index.htm index.php;  
-         root            /home/htdocs;  
-         access_log      /home/logs/access_ycan.com.log  access;  
-         location ~ .*\.(php|php5)?$  
-             {  
-                 try_files $uri =404;  
- #               fastcgi_pass  unix:/tmp/php-cgi.sock;  
-                 fastcgi_pass  127.0.0.1:9000;  
-                 fastcgi_index index.php;  
-                 include       fcgi.conf;  
-             }  
-         location /status {  
-             stub_status on;  
-             access_log   off;  
-         }  
-         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$  
-             {  
-                 expires      30d;  
-                 access_log   off;  
-             }  
-         location ~ .*\.(js|css)?$  
-             {  
-                 expires      12h;  
-                 access_log   off;  
-             }  
-     }  
- # include vhost/*.conf;  
- }  
3. fcgi. conf 설정
  
  
  
  
   
   
   
   - fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;  
- fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;  
- fastcgi_param  QUERY_STRING       $query_string;  
- fastcgi_param  REQUEST_METHOD     $request_method;  
- fastcgi_param  CONTENT_TYPE       $content_type;  
- fastcgi_param  CONTENT_LENGTH     $content_length;  
- fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;  
- fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;  
- fastcgi_param  REQUEST_URI        $request_uri;  
- fastcgi_param  DOCUMENT_URI       $document_uri;  
- fastcgi_param  DOCUMENT_ROOT      $document_root;  
- fastcgi_param  SERVER_PROTOCOL    $server_protocol;  
- fastcgi_param  REMOTE_ADDR        $remote_addr;  
- fastcgi_param  REMOTE_PORT        $remote_port;  
- fastcgi_param  SERVER_ADDR        $server_addr;  
- fastcgi_param  SERVER_PORT        $server_port;  
- fastcgi_param  SERVER_NAME        $server_name;  
- # PHP only, required if PHP was built with--enable-force-cgi-redirect 
- fastcgi_param  REDIRECT_STATUS    200;  
3. nginx 시작 스 크 립 트
  
  
  
  
   
   
   
   - #!/bin/sh  
- #  
- # nginx - this script starts and stops the nginx daemin  
- #  
- # chkconfig:   - 85 15   
- # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \  
- #               proxy and IMAP/POP3 proxy server  
- # processname: nginx  
- # config:      /usr/local/nginx/conf/nginx.conf  
- # pidfile:     /usr/local/nginx/logs/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/local/nginx/sbin/nginx" 
- prog=$(basename $nginx)   
- NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" 
- lockfile=/var/lock/subsys/nginx  
- start() {  
-     [ -x $nginx ] || exit 5  
-     [ -f $NGINX_CONF_FILE ] || exit 6  
-     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 2  
-     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