v_add_web_domain_nginx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/bash
  2. # info: add webdomain nginx support
  3. # options: user domain
  4. #
  5. # The function enables nginx support for a domain. It can significantly improve
  6. # website speed.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument defenition
  11. user=$1
  12. domain=$(idn -t --quiet -u "$2" )
  13. domain_idn=$(idn -t --quiet -a "$domain")
  14. template=${3-default}
  15. default_extentions="jpg,jpeg,gif,png,ico,css,zip,tgz,gz,rar,bz2,doc,xls,exe,\
  16. pdf,ppt,txt,tar,wav,bmp,rtf,js,mp3,avi,mpeg,html,htm"
  17. extentions=${4-$default_extentions}
  18. # Importing variables
  19. source $VESTA/conf/vars.conf
  20. source $V_CONF/vesta.conf
  21. source $V_FUNC/shared.func
  22. source $V_FUNC/domain.func
  23. #----------------------------------------------------------#
  24. # Verifications #
  25. #----------------------------------------------------------#
  26. # Checking arg number
  27. check_args '2' "$#" 'user domain [template] [extentions]'
  28. # Checking argument format
  29. format_validation 'user' 'domain' 'template' 'extentions'
  30. # Checking proxy system is enabled
  31. is_system_enabled 'proxy'
  32. # Checking user
  33. is_user_valid
  34. # Checking user is active
  35. is_user_suspended
  36. # Checking domain exist
  37. is_web_domain_valid
  38. # Checking domain is not suspened
  39. is_domain_suspended 'web'
  40. # Check nginx is not added
  41. is_web_domain_key_empty '$NGINX'
  42. # Checking template
  43. is_template_valid "proxy"
  44. #----------------------------------------------------------#
  45. # Action #
  46. #----------------------------------------------------------#
  47. # Defining domain parameters
  48. get_web_domain_values
  49. NGINX="$template"
  50. NGINX_EXT="$extentions"
  51. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
  52. conf="$V_HOME/$user/conf/nginx.conf"
  53. # Preparing domain values for the template substitution
  54. upd_web_domain_values
  55. add_web_config
  56. # Checking main vesta httpd config
  57. main_conf='/etc/nginx/conf.d/vesta_users.conf'
  58. main_conf_check=$(grep "$conf" $main_conf )
  59. if [ -z "$main_conf_check" ]; then
  60. echo "include $conf;" >>$main_conf
  61. fi
  62. if [ "$SSL" = 'yes' ]; then
  63. proxy_string="proxy_pass https://$ip:$WEB_SSL_PORT;"
  64. tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
  65. conf="$V_HOME/$user/conf/snginx.conf"
  66. add_web_config
  67. main_conf='/etc/nginx/conf.d/vesta_users.conf'
  68. main_conf_check=$(grep "$conf" $main_conf )
  69. if [ -z "$main_conf_check" ]; then
  70. echo "include $conf;" >>$main_conf
  71. fi
  72. fi
  73. #----------------------------------------------------------#
  74. # Vesta #
  75. #----------------------------------------------------------#
  76. # Adding nginx params to config
  77. update_web_domain_value '$NGINX' "$NGINX"
  78. update_web_domain_value '$NGINX_EXT' "$extentions"
  79. # Adding task to the vesta pipe
  80. restart_schedule 'web'
  81. log_history "$V_EVENT" "v_delete_web_domain_nginx $user $domain"
  82. log_event 'system' "$V_EVENT"
  83. exit