v_add_web_domain_nginx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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-default}
  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' 'template' '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. is_nginx_template_valid
  35. #----------------------------------------------------------#
  36. # Action #
  37. #----------------------------------------------------------#
  38. # Defining domain parameters
  39. get_domain_values 'web'
  40. NGINX="$template"
  41. NGINX_EXT="$extentions"
  42. tpl_file="$WEBTPL/ngingx_$NGINX.tpl"
  43. conf="$HOMEDIR/$user/conf/web/nginx.conf"
  44. # Preparing domain values for the template substitution
  45. upd_web_domain_values
  46. add_web_config
  47. # Set permission and ownership
  48. chown root:nginx $conf
  49. chmod 640 $conf
  50. # Checking main vesta httpd config
  51. main_conf='/etc/nginx/conf.d/vesta_users.conf'
  52. main_conf_check=$(grep "$conf" $main_conf )
  53. if [ -z "$main_conf_check" ]; then
  54. echo "include $conf;" >>$main_conf
  55. fi
  56. # Checking ssl
  57. if [ "$SSL" = 'yes' ]; then
  58. tpl_file="$WEBTPL/ngingx_$NGINX.stpl"
  59. conf="$HOMEDIR/$user/conf/web/snginx.conf"
  60. add_web_config
  61. chown root:nginx $conf
  62. chmod 640 $conf
  63. main_conf='/etc/nginx/conf.d/vesta_users.conf'
  64. main_conf_check=$(grep "$conf" $main_conf )
  65. if [ -z "$main_conf_check" ]; then
  66. echo "include $conf;" >>$main_conf
  67. fi
  68. fi
  69. #----------------------------------------------------------#
  70. # Vesta #
  71. #----------------------------------------------------------#
  72. # Update config
  73. update_object_value 'web' 'DOMAIN' "$domain" '$NGINX' "$NGINX"
  74. update_object_value 'web' 'DOMAIN' "$domain" '$NGINX_EXT' "$extentions"
  75. # Restart web server
  76. if [ "$restart" != 'no' ]; then
  77. $BIN/v_restart_web "$EVENT"
  78. fi
  79. log_history "$EVENT"
  80. log_event "$OK" "$EVENT"
  81. exit