v-add-web-domain-nginx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/bash
  2. # info: add webdomain nginx support
  3. # options: user domain [template] [extentions] [restart]
  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
  15. default_extentions="jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls,\
  16. exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm"
  17. extentions=${4-$default_extentions}
  18. restart="$5"
  19. # Includes
  20. source $VESTA/conf/vesta.conf
  21. source $VESTA/func/main.sh
  22. source $VESTA/func/domain.sh
  23. #----------------------------------------------------------#
  24. # Verifications #
  25. #----------------------------------------------------------#
  26. check_args '2' "$#" 'user domain [template] [extentions] [restart]'
  27. validate_format 'user' 'domain' 'extentions'
  28. is_system_enabled "$PROXY_SYSTEM"
  29. is_object_valid 'user' 'USER' "$user"
  30. is_object_unsuspended 'user' 'USER' "$user"
  31. is_object_valid 'web' 'DOMAIN' "$domain"
  32. is_object_unsuspended 'web' 'DOMAIN' "$domain"
  33. is_object_value_empty 'web' 'DOMAIN' "$domain" '$NGINX'
  34. if [ ! -z "$template" ]; then
  35. validate_format 'template'
  36. is_nginx_template_valid
  37. else
  38. template=$(get_user_value '$TEMPLATE')
  39. is_nginx_template_valid
  40. fi
  41. #----------------------------------------------------------#
  42. # Action #
  43. #----------------------------------------------------------#
  44. # Defining domain parameters
  45. get_domain_values 'web'
  46. NGINX="$template"
  47. NGINX_EXT="$extentions"
  48. tpl_file="$WEBTPL/nginx_$NGINX.tpl"
  49. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  50. # Preparing domain values for the template substitution
  51. upd_web_domain_values
  52. add_web_config
  53. # Set permission and ownership
  54. chown root:nginx $conf
  55. chmod 640 $conf
  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. # Checking ssl
  63. if [ "$SSL" = 'yes' ]; then
  64. tpl_file="$WEBTPL/nginx_$NGINX.stpl"
  65. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  66. add_web_config
  67. chown root:nginx $conf
  68. chmod 640 $conf
  69. main_conf='/etc/nginx/conf.d/vesta_users.conf'
  70. main_conf_check=$(grep "$conf" $main_conf )
  71. if [ -z "$main_conf_check" ]; then
  72. echo "include $conf;" >>$main_conf
  73. fi
  74. fi
  75. #----------------------------------------------------------#
  76. # Vesta #
  77. #----------------------------------------------------------#
  78. # Update config
  79. update_object_value 'web' 'DOMAIN' "$domain" '$NGINX' "$NGINX"
  80. update_object_value 'web' 'DOMAIN' "$domain" '$NGINX_EXT' "$extentions"
  81. # Restart web server
  82. if [ "$restart" != 'no' ]; then
  83. $BIN/v-restart-web "$EVENT"
  84. fi
  85. log_history "enabled nginx support for $domain"
  86. log_event "$OK" "$EVENT"
  87. exit