1
0

openresty.sh 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. # https://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Install_OpenResty() {
  11. pushd ${oneinstack_dir}/src
  12. id -u $run_user >/dev/null 2>&1
  13. [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user
  14. tar xzf pcre-$pcre_version.tar.gz
  15. tar xzf openresty-$openresty_version.tar.gz
  16. tar xzf openssl-$openssl_version.tar.gz
  17. pushd openresty-$openresty_version
  18. # close debug
  19. openresty_version_tmp=${openresty_version%.*}
  20. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' bundle/nginx-$openresty_version_tmp/auto/cc/gcc # close debug
  21. [ ! -d "$openresty_install_dir" ] && mkdir -p $openresty_install_dir
  22. ./configure --prefix=$openresty_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_version --with-pcre=../pcre-$pcre_version --with-pcre-jit --with-ld-opt='-ljemalloc' $nginx_modules_options
  23. make -j ${THREAD} && make install
  24. if [ -e "$openresty_install_dir/nginx/conf/nginx.conf" ]; then
  25. popd
  26. rm -rf openresty-$openresty_version
  27. echo "${CSUCCESS}OpenResty installed successfully! ${CEND}"
  28. else
  29. rm -rf $openresty_install_dir
  30. echo "${CFAILURE}OpenResty install failed, Please Contact the author! ${CEND}"
  31. kill -9 $$
  32. fi
  33. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$openresty_install_dir/nginx/sbin:\$PATH" >> /etc/profile
  34. [ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep $openresty_install_dir /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=$openresty_install_dir/nginx/sbin:\1@" /etc/profile
  35. . /etc/profile
  36. [ "$OS" == 'CentOS' ] && { /bin/cp ../init.d/Nginx-init-CentOS /etc/init.d/nginx; chkconfig --add nginx; chkconfig nginx on; }
  37. [[ $OS =~ ^Ubuntu$|^Debian$ ]] && { /bin/cp ../init.d/Nginx-init-Ubuntu /etc/init.d/nginx; update-rc.d nginx defaults; }
  38. sed -i "s@/usr/local/nginx@$openresty_install_dir/nginx@g" /etc/init.d/nginx
  39. mv $openresty_install_dir/nginx/conf/nginx.conf{,_bk}
  40. if [[ $Apache_version =~ ^[1-2]$ ]]; then
  41. /bin/cp ../config/nginx_apache.conf $openresty_install_dir/nginx/conf/nginx.conf
  42. elif [[ $Tomcat_version =~ ^[1-2]$ ]] && [ ! -e "$php_install_dir/bin/php" ]; then
  43. /bin/cp ../config/nginx_tomcat.conf $openresty_install_dir/nginx/conf/nginx.conf
  44. else
  45. /bin/cp ../config/nginx.conf $openresty_install_dir/nginx/conf/nginx.conf
  46. [ "$PHP_yn" == 'y' ] && [ -z "`grep '/php-fpm_status' $openresty_install_dir/nginx/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 }@" $openresty_install_dir/nginx/conf/nginx.conf
  47. fi
  48. cat > $openresty_install_dir/nginx/conf/proxy.conf << EOF
  49. proxy_connect_timeout 300s;
  50. proxy_send_timeout 900;
  51. proxy_read_timeout 900;
  52. proxy_buffer_size 32k;
  53. proxy_buffers 4 64k;
  54. proxy_busy_buffers_size 128k;
  55. proxy_redirect off;
  56. proxy_hide_header Vary;
  57. proxy_set_header Accept-Encoding '';
  58. proxy_set_header Referer \$http_referer;
  59. proxy_set_header Cookie \$http_cookie;
  60. proxy_set_header Host \$host;
  61. proxy_set_header X-Real-IP \$remote_addr;
  62. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  63. EOF
  64. sed -i "s@/data/wwwroot/default@$wwwroot_dir/default@" $openresty_install_dir/nginx/conf/nginx.conf
  65. sed -i "s@/data/wwwlogs@$wwwlogs_dir@g" $openresty_install_dir/nginx/conf/nginx.conf
  66. sed -i "s@^user www www@user $run_user $run_user@" $openresty_install_dir/nginx/conf/nginx.conf
  67. # logrotate nginx log
  68. cat > /etc/logrotate.d/nginx << EOF
  69. $wwwlogs_dir/*nginx.log {
  70. daily
  71. rotate 5
  72. missingok
  73. dateext
  74. compress
  75. notifempty
  76. sharedscripts
  77. postrotate
  78. [ -e /var/run/nginx.pid ] && kill -USR1 \`cat /var/run/nginx.pid\`
  79. endscript
  80. }
  81. EOF
  82. popd
  83. ldconfig
  84. service nginx start
  85. }