nginx.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # http://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Install_Nginx() {
  11. cd $oneinstack_dir/src
  12. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
  13. src_url=http://nginx.org/download/nginx-$nginx_version.tar.gz && Download_src
  14. tar xzf pcre-$pcre_version.tar.gz
  15. cd pcre-$pcre_version
  16. ./configure
  17. make && make install
  18. cd ..
  19. id -u $run_user >/dev/null 2>&1
  20. [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user
  21. tar xzf nginx-$nginx_version.tar.gz
  22. cd nginx-$nginx_version
  23. # Modify Nginx version
  24. #sed -i 's@#define NGINX_VERSION.*$@#define NGINX_VERSION "1.2"@' src/core/nginx.h
  25. #sed -i 's@#define NGINX_VER.*NGINX_VERSION$@#define NGINX_VER "Linuxeye/" NGINX_VERSION@' src/core/nginx.h
  26. #sed -i 's@Server: nginx@Server: linuxeye@' src/http/ngx_http_header_filter_module.c
  27. # close debug
  28. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc
  29. if [ "$je_tc_malloc" == '1' ];then
  30. malloc_module="--with-ld-opt='-ljemalloc'"
  31. elif [ "$je_tc_malloc" == '2' ];then
  32. malloc_module='--with-google_perftools_module'
  33. mkdir /tmp/tcmalloc
  34. chown -R ${run_user}.$run_user /tmp/tcmalloc
  35. fi
  36. [ ! -d "$nginx_install_dir" ] && mkdir -p $nginx_install_dir
  37. ./configure --prefix=$nginx_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module $malloc_module
  38. make && make install
  39. if [ -e "$nginx_install_dir/conf/nginx.conf" ];then
  40. cd ..
  41. rm -rf nginx-$nginx_version
  42. echo "${CSUCCESS}Nginx install successfully! ${CEND}"
  43. else
  44. rm -rf $nginx_install_dir
  45. echo "${CFAILURE}Nginx install failed, Please Contact the author! ${CEND}"
  46. kill -9 $$
  47. fi
  48. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$nginx_install_dir/sbin:\$PATH" >> /etc/profile
  49. [ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep $nginx_install_dir /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=$nginx_install_dir/sbin:\1@" /etc/profile
  50. . /etc/profile
  51. [ "$OS" == 'CentOS' ] && { /bin/cp ../init.d/Nginx-init-CentOS /etc/init.d/nginx; chkconfig --add nginx; chkconfig nginx on; }
  52. [[ $OS =~ ^Ubuntu$|^Debian$ ]] && { /bin/cp ../init.d/Nginx-init-Ubuntu /etc/init.d/nginx; update-rc.d nginx defaults; }
  53. cd ..
  54. sed -i "s@/usr/local/nginx@$nginx_install_dir@g" /etc/init.d/nginx
  55. mv $nginx_install_dir/conf/nginx.conf{,_bk}
  56. if [[ $Apache_version =~ ^[1-2]$ ]];then
  57. /bin/cp config/nginx_apache.conf $nginx_install_dir/conf/nginx.conf
  58. elif [[ $Tomcat_version =~ ^[1-2]$ ]] && [ ! -e "$php_install_dir/bin/php" ];then
  59. /bin/cp config/nginx_tomcat.conf $nginx_install_dir/conf/nginx.conf
  60. else
  61. /bin/cp config/nginx.conf $nginx_install_dir/conf/nginx.conf
  62. [ "$PHP_yn" == 'y' ] && [ -z "`grep '/php-fpm_status' $nginx_install_dir/conf/nginx.conf`" ] && sed -i "s@index index.html index.php;@index index.html index.php;\n location ~ /php-fpm_status {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n allow 127.0.0.1;\n deny all;\n }@" $nginx_install_dir/conf/nginx.conf
  63. fi
  64. cat > $nginx_install_dir/conf/proxy.conf << EOF
  65. proxy_connect_timeout 300s;
  66. proxy_send_timeout 900;
  67. proxy_read_timeout 900;
  68. proxy_buffer_size 32k;
  69. proxy_buffers 4 64k;
  70. proxy_busy_buffers_size 128k;
  71. proxy_redirect off;
  72. proxy_hide_header Vary;
  73. proxy_set_header Accept-Encoding '';
  74. proxy_set_header Referer \$http_referer;
  75. proxy_set_header Cookie \$http_cookie;
  76. proxy_set_header Host \$host;
  77. proxy_set_header X-Real-IP \$remote_addr;
  78. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  79. EOF
  80. sed -i "s@/data/wwwroot/default@$wwwroot_dir/default@" $nginx_install_dir/conf/nginx.conf
  81. sed -i "s@/data/wwwlogs@$wwwlogs_dir@g" $nginx_install_dir/conf/nginx.conf
  82. sed -i "s@^user www www@user $run_user $run_user@" $nginx_install_dir/conf/nginx.conf
  83. [ "$je_tc_malloc" == '2' ] && sed -i 's@^pid\(.*\)@pid\1\ngoogle_perftools_profiles /tmp/tcmalloc;@' $nginx_install_dir/conf/nginx.conf
  84. # logrotate nginx log
  85. cat > /etc/logrotate.d/nginx << EOF
  86. $wwwlogs_dir/*nginx.log {
  87. daily
  88. rotate 5
  89. missingok
  90. dateext
  91. compress
  92. notifempty
  93. sharedscripts
  94. postrotate
  95. [ -e /var/run/nginx.pid ] && kill -USR1 \`cat /var/run/nginx.pid\`
  96. endscript
  97. }
  98. EOF
  99. ldconfig
  100. service nginx start
  101. }