lnmp 원 키 설치 - nginx

23560 단어 nginx 원 키 설치
1. 원 클릭 으로 설 치 된 스 크 립 트

  
  
  
  
  1. #!/bin/bash

  2. #version 1.0

  3. #date    2013-05-04

  4. #author  yangcan

  5. #mail    [email protected]

  6. _work_path=`pwd`

  7. # user define

  8. _nginx_path=/usr/local/nginx

  9. _nginx_user=ycan

  10. _nginx_group=ycan

  11. [ id $_nginx_user >/dev/null 2>&1 ] || useradd -r -s /sbin/nologin $_nginx_user

  12. mkdir /var/tmp/tcmalloc/ && chmod -R  777 /var/tmp/tcmalloc/

  13. mkdir /var/tmp/nginx_body

  14. mkdir /var/tmp/proxy_temp

  15. mkdir /var/tmp/fastcgi_temp

  16. mkdir /var/tmp/uwsgi_temp

  17. mkdir /var/tmp/scgi_temp

  18. chown -R $_nginx_user:$_nginx_group /var/tmp/*

  19. _check_stats() {

  20.        if [ $? == 0 ];then

  21.                echo "*************************************" >>$_work_path/install.log

  22.                echo "$1 : at $(date +'%F %T') install OK "  >>$_work_path/install.log

  23. else

  24.                echo "*************************************" >>$_work_path/install.log

  25.                echo "$1 : at $(date +'%F %T') install               <<FAIL>> "  >>$_work_path/install.log

  26.        fi

  27. }

  28. _check_file() {

  29. ( yum grouplist|grep -B 100 "Available Groups:"|grep "Development Libraries" ) || yum groupinstall "Development Libraries"

  30. ( yum grouplist|grep -B 100 "Available Groups:"|grep "Development Tools" ) || yum groupinstall "Development Tools"

  31. yum -y install perl-devel perl-ExtUtils-Embed

  32. [ -s libunwind-1.1.tar.gz ] || wget -c http://ftp.twaren.net/Unix/NonGNU//libunwind/libunwind-1.1.tar.gz

  33. [ -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

  34. [ -s pcre-8.32.tar.gz ] || wget -c http://nchc.dl.sourceforge.net/project/pcre/pcre/8.32/pcre-8.32.tar.gz

  35. [ -s nginx-1.2.8.tar.gz ] || wget -c http://nginx.org/download/nginx-1.2.8.tar.gz

  36. [ -s gperftools-2.0.tar.gz ] || wget -c https://gperftools.googlecode.com/files/gperftools-2.0.tar.gz

  37. }

  38. _install_nginx_depth() {

  39. cd $_work_path

  40. tar zxf pcre-8.32.tar.gz  

  41. cd pcre-8.32

  42. ./configure

  43. make && make install

  44. _check_stats pcre-8.32

  45. /sbin/ldconfig

  46. # 64bit need,but 32bits not need.

  47. cd $_work_path

  48. tar zxf libunwind-1.1.tar.gz  

  49. cd libunwind-1.1

  50. ./configure --enable-shared

  51. make && make install

  52. _check_stats libunwind-1.1

  53. cd $_work_path

  54. tar zxf  gperftools-2.0.tar.gz  

  55. cd gperftools-2.0  

  56. ./configure --enable-shared --enable-frame-pointers

  57. make && make install

  58. _check_stats gperftools-2.0

  59. /sbin/ldconfig

  60. }

  61. _install_nginx() {

  62. cd $_work_path

  63. tar zxf nginx-1.2.8.tar.gz    

  64. cd nginx-1.2.8

  65. ./configure --prefix=$_nginx_path --user=$_nginx_user --group=$_nginx_group \

  66. --with-pcre \

  67. --with-http_ssl_module \

  68. --with-http_realip_module \

  69. --with-http_sub_module  \

  70. --with-http_flv_module  \

  71. --with-http_gzip_static_module  \

  72. --with-http_stub_status_module  \

  73. --with-http_perl_module \

  74. --with-google_perftools_module \

  75. --http-client-body-temp-path=/var/tmp/nginx_body \

  76. --http-proxy-temp-path=/var/tmp/proxy_temp \

  77. --http-fastcgi-temp-path=/var/tmp/fastcgi_temp \

  78. --http-uwsgi-temp-path=/var/tmp/uwsgi_temp \

  79. --http-scgi-temp-path=/var/tmp/scgi_temp \

  80. --without-mail_pop3_module \

  81. --without-mail_imap_module \

  82. --without-mail_smtp_module \

  83. --pid-path=/var/run/nginx.pid

  84. [ $? == 0 ] && make  

  85. [ $? == 0 ] && make install

  86. _check_stats nginx

  87. }

  88. if [ `id -u` -ne 0 ];then

  89.    echo "install nginx need root"

  90.    exit 1

  91. else

  92.    _check_file

  93.    _install_nginx_depth

  94.    _install_nginx

  95.    [ $? -eq 0 ] && echo " $(date +"%F %T")  @@@@@@@ nginx COMPLETE  @@@@@@ " >> $_work_path/install.log

  96.    sleep 5

  97. fi


2. nginx. conf 설정

  
  
  
  
  1. user ycan ycan;

  2. worker_processes 8;

  3. worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

  4. error_log  /home/logs/error.log notice;

  5. #error_log  /usr/local/nginx/logs/error.log  notice;

  6. #error_log  /usr/local/nginx/logs/error.log  info;

  7. #pid        logs/nginx.pid;

  8. worker_rlimit_nofile 65535;

  9. events {

  10.    use epoll;

  11.    worker_connections 30000;

  12. }

  13. http {

  14.    include       mime.types;

  15.    default_type  application/octet-stream;

  16.    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '

  17. '$status $body_bytes_sent "$http_referer" '

  18. '"$http_user_agent" "$http_x_forwarded_for"';

  19.    #access_log  logs/access.log  main;

  20.    sendfile            on;

  21.    tcp_nopush          on;

  22.    tcp_nodelay         on;

  23.    keepalive_timeout   60;

  24.    #ip_hash;

  25.    ignore_invalid_headers   on;

  26.    recursive_error_pages    on;

  27.    server_name_in_redirect off;

  28.    server_tokens           off;

  29.    gzip on;

  30.    gzip_comp_level     9;

  31.    gzip_min_length     1100;

  32.    gzip_buffers        4 8k;

  33.    gzip_http_version   1.1;

  34.    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

  35.    server_names_hash_bucket_size   256;

  36.    client_header_buffer_size       16K;

  37.    large_client_header_buffers     4 64k;

  38.    client_max_body_size            50m;

  39.    client_body_buffer_size         256k;

  40.    client_header_timeout           5m;

  41.    client_body_timeout             3m;

  42.    send_timeout                    5m;

  43.    open_file_cache max=204800 inactive=20s;

  44.    open_file_cache_min_uses 1;

  45.    open_file_cache_valid 30s;

  46.    fastcgi_intercept_errors on;

  47.    server {

  48.        listen 80 default;

  49.        server_name _;

  50. return 444;

  51.    }

  52.    server

  53.    {

  54.        listen          80;

  55.        server_name     www.ycan.com;

  56. indexindex.html index.htm index.php;

  57.        root            /home/htdocs;

  58.        access_log      /home/logs/access_ycan.com.log  access;

  59.        location ~ .*\.(php|php5)?$

  60.            {

  61.                try_files $uri =404;

  62. #               fastcgi_pass  unix:/tmp/php-cgi.sock;

  63.                fastcgi_pass  127.0.0.1:9000;

  64.                fastcgi_index index.php;

  65.                include       fcgi.conf;

  66.            }

  67.        location /status {

  68.            stub_status on;

  69.            access_log   off;

  70.        }

  71.        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

  72.            {

  73.                expires      30d;

  74.                access_log   off;

  75.            }

  76.        location ~ .*\.(js|css)?$

  77.            {

  78.                expires      12h;

  79.                access_log   off;

  80.            }

  81.    }

  82. # include vhost/*.conf;

  83. }


3. fcgi. conf 설정

  
  
  
  
  1. fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

  2. fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

  3. fastcgi_param  QUERY_STRING       $query_string;

  4. fastcgi_param  REQUEST_METHOD     $request_method;

  5. fastcgi_param  CONTENT_TYPE       $content_type;

  6. fastcgi_param  CONTENT_LENGTH     $content_length;

  7. fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

  8. fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

  9. fastcgi_param  REQUEST_URI        $request_uri;

  10. fastcgi_param  DOCUMENT_URI       $document_uri;

  11. fastcgi_param  DOCUMENT_ROOT      $document_root;

  12. fastcgi_param  SERVER_PROTOCOL    $server_protocol;

  13. fastcgi_param  REMOTE_ADDR        $remote_addr;

  14. fastcgi_param  REMOTE_PORT        $remote_port;

  15. fastcgi_param  SERVER_ADDR        $server_addr;

  16. fastcgi_param  SERVER_PORT        $server_port;

  17. fastcgi_param  SERVER_NAME        $server_name;

  18. # PHP only, required if PHP was built with--enable-force-cgi-redirect

  19. fastcgi_param  REDIRECT_STATUS    200;


3. nginx 시작 스 크 립 트

  
  
  
  
  1. #!/bin/sh

  2. #

  3. # nginx - this script starts and stops the nginx daemin

  4. #

  5. # chkconfig:   - 85 15  

  6. # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \

  7. #               proxy and IMAP/POP3 proxy server

  8. # processname: nginx

  9. # config:      /usr/local/nginx/conf/nginx.conf

  10. # pidfile:     /usr/local/nginx/logs/nginx.pid

  11. # Source function library.

  12. . /etc/rc.d/init.d/functions

  13. # Source networking configuration.

  14. . /etc/sysconfig/network

  15. # Check that networking is up.

  16. [ "$NETWORKING" = "no" ] && exit 0

  17. nginx="/usr/local/nginx/sbin/nginx"

  18. prog=$(basename $nginx)  

  19. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

  20. lockfile=/var/lock/subsys/nginx

  21. start() {

  22.    [ -x $nginx ] || exit 5

  23.    [ -f $NGINX_CONF_FILE ] || exit 6

  24.    echo -n $"Starting $prog: "

  25.    daemon $nginx -c $NGINX_CONF_FILE

  26.    retval=$?

  27.    echo

  28.    [ $retval -eq 0 ] && touch $lockfile

  29. return $retval

  30. }

  31. stop() {

  32.    echo -n $"Stopping $prog: "

  33.    killproc $prog -QUIT

  34.    retval=$?

  35.    echo

  36.    [ $retval -eq 0 ] && rm -f $lockfile

  37. return $retval

  38. }

  39. restart() {

  40.    configtest || return $?

  41.    stop

  42.    sleep 2

  43.    start

  44. }

  45. reload() {

  46.    configtest || return $?

  47.    echo -n $"Reloading $prog: "

  48.    killproc $nginx -HUP

  49.    RETVAL=$?

  50.    echo

  51. }

  52. force_reload() {

  53.    restart

  54. }

  55. configtest() {

  56.  $nginx -t -c $NGINX_CONF_FILE

  57. }

  58. rh_status() {

  59.    status $prog

  60. }

  61. rh_status_q() {

  62.    rh_status >/dev/null 2>&1

  63. }

  64. case"$1"in

  65.    start)

  66.        rh_status_q && exit 0

  67.        $1

  68.        ;;

  69.    stop)

  70.        rh_status_q || exit 0

  71.        $1

  72.        ;;

  73.    restart|configtest)

  74.        $1

  75.        ;;

  76.    reload)

  77.        rh_status_q || exit 7

  78.        $1

  79.        ;;

  80. force-reload)

  81.        force_reload

  82.        ;;

  83.    status)

  84.        rh_status

  85.        ;;

  86.    condrestart|try-restart)

  87.        rh_status_q || exit 0

  88.            ;;

  89.    *)

  90.        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

  91.        exit 2

  92. esac

좋은 웹페이지 즐겨찾기