nginx.sh 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 6+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Install_Nginx() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. id -u ${run_user} >/dev/null 2>&1
  13. [ $? -ne 0 ] && useradd -M -s /sbin/nologin ${run_user}
  14. tar xzf pcre-$pcre_ver.tar.gz
  15. tar xzf nginx-$nginx_ver.tar.gz
  16. tar xzf openssl-$openssl_ver.tar.gz
  17. pushd nginx-$nginx_ver
  18. # Modify Nginx version
  19. #sed -i 's@#define NGINX_VERSION.*$@#define NGINX_VERSION "1.2"@' src/core/nginx.h
  20. #sed -i 's@#define NGINX_VER.*NGINX_VERSION$@#define NGINX_VER "Linuxeye/" NGINX_VERSION@' src/core/nginx.h
  21. #sed -i 's@Server: nginx@Server: linuxeye@' src/http/ngx_http_header_filter_module.c
  22. # close debug
  23. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc
  24. [ ! -d "$nginx_install_dir" ] && mkdir -p $nginx_install_dir
  25. ./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-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-$openssl_ver --with-pcre=../pcre-$pcre_ver --with-pcre-jit --with-ld-opt='-ljemalloc' $nginx_modules_options
  26. make -j ${THREAD} && make install
  27. if [ -e "$nginx_install_dir/conf/nginx.conf" ]; then
  28. popd
  29. rm -rf nginx-$nginx_ver
  30. echo "${CSUCCESS}Nginx installed successfully! ${CEND}"
  31. else
  32. rm -rf $nginx_install_dir
  33. echo "${CFAILURE}Nginx install failed, Please Contact the author! ${CEND}"
  34. kill -9 $$
  35. fi
  36. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$nginx_install_dir/sbin:\$PATH" >> /etc/profile
  37. [ -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
  38. . /etc/profile
  39. [ "$OS" == 'CentOS' ] && { /bin/cp ../init.d/Nginx-init-CentOS /etc/init.d/nginx; chkconfig --add nginx; chkconfig nginx on; }
  40. [[ $OS =~ ^Ubuntu$|^Debian$ ]] && { /bin/cp ../init.d/Nginx-init-Ubuntu /etc/init.d/nginx; update-rc.d nginx defaults; }
  41. sed -i "s@/usr/local/nginx@$nginx_install_dir@g" /etc/init.d/nginx
  42. mv $nginx_install_dir/conf/nginx.conf{,_bk}
  43. if [[ ${apache_option} =~ ^[1-2]$ ]]; then
  44. /bin/cp ../config/nginx_apache.conf $nginx_install_dir/conf/nginx.conf
  45. elif [[ ${tomcat_option} =~ ^[1-2]$ ]] && [ ! -e "${php_install_dir}/bin/php" ]; then
  46. /bin/cp ../config/nginx_tomcat.conf $nginx_install_dir/conf/nginx.conf
  47. else
  48. /bin/cp ../config/nginx.conf $nginx_install_dir/conf/nginx.conf
  49. [ "$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
  50. fi
  51. cat > $nginx_install_dir/conf/proxy.conf << EOF
  52. proxy_connect_timeout 300s;
  53. proxy_send_timeout 900;
  54. proxy_read_timeout 900;
  55. proxy_buffer_size 32k;
  56. proxy_buffers 4 64k;
  57. proxy_busy_buffers_size 128k;
  58. proxy_redirect off;
  59. proxy_hide_header Vary;
  60. proxy_set_header Accept-Encoding '';
  61. proxy_set_header Referer \$http_referer;
  62. proxy_set_header Cookie \$http_cookie;
  63. proxy_set_header Host \$host;
  64. proxy_set_header X-Real-IP \$remote_addr;
  65. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  66. proxy_set_header X-Forwarded-Proto \$scheme;
  67. EOF
  68. sed -i "s@/data/wwwroot/default@${wwwroot_dir}/default@" $nginx_install_dir/conf/nginx.conf
  69. sed -i "s@/data/wwwlogs@${wwwlogs_dir}@g" $nginx_install_dir/conf/nginx.conf
  70. sed -i "s@^user www www@user ${run_user} ${run_user}@" $nginx_install_dir/conf/nginx.conf
  71. # logrotate nginx log
  72. cat > /etc/logrotate.d/nginx << EOF
  73. ${wwwlogs_dir}/*nginx.log {
  74. daily
  75. rotate 5
  76. missingok
  77. dateext
  78. compress
  79. notifempty
  80. sharedscripts
  81. postrotate
  82. [ -e /var/run/nginx.pid ] && kill -USR1 \`cat /var/run/nginx.pid\`
  83. endscript
  84. }
  85. EOF
  86. popd
  87. ldconfig
  88. service nginx start
  89. }