Bladeren bron

added nginx support per domain

Serghey Rodin 14 jaren geleden
bovenliggende
commit
495d3f7a18
3 gewijzigde bestanden met toevoegingen van 39 en 48 verwijderingen
  1. 35 42
      bin/v_add_web_domain_nginx
  2. 2 3
      data/templates/ngingx_vhost_default.stpl
  3. 2 3
      data/templates/ngingx_vhost_default.tpl

+ 35 - 42
bin/v_add_web_domain_nginx

@@ -1,5 +1,5 @@
 #!/bin/bash
-# info: adding web domain nginx integration
+# info: adding nginx support
 
 #----------------------------------------------------------#
 #                    Variable&Function                     #
@@ -9,10 +9,9 @@
 user="$1"
 domain="$2"
 template="${3-default}"
-default_extentions="jpg jpeg gif png ico css zip tgz gz rar bz2 doc xls exe\
- pdf ppt txt tar wav bmp rtf js mp3 avi mpeg"
+default_extentions="jpg,jpeg,gif,png,ico,css,zip,tgz,gz,rar,bz2,doc,xls,exe,\
+pdf,ppt,txt,tar,wav,bmp,rtf,js,mp3,avi,mpeg"
 extentions="${4-$default_extentions}"
-extentions=${extentions// /|}     # replacing spaces with pipe char
 
 # Importing variables
 source $VESTA/conf/vars.conf
@@ -25,12 +24,12 @@ source $V_FUNC/domain_func.sh
 #----------------------------------------------------------#
 
 # Checking arg number
-check_args '2' "$#" 'user domain [template] [extentions] [conn]'
+check_args '2' "$#" 'user domain [template] [extentions]'
 
 # Checking argument format
 format_validation 'user' 'domain' 'template' 'extentions'
 
-# Checking web system is enabled
+# Checking proxy system is enabled
 is_system_enabled 'proxy'
 
 # Checking user
@@ -52,47 +51,40 @@ is_web_domain_key_empty '$NGINX'
 is_template_valid "proxy"
 
 
-exit
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
-# Get template name
-tpl_name=$(get_web_domain_value '$TPL')
-tpl_file="$V_WEBTPL/$package-$tpl_name.tpl"
-
-# Defining config
-conf="$V_HOME/$user/conf/httpd.conf"
-
-# Defining search phrase
-search_phrase='ServerAlias'
-
-# Defining new alias string
-curr_alias=$(get_web_domain_value '$ALIAS')
-if [ -z "$curr_alias" ]; then
-    new_alias="$dom_alias"
+# Defining domain parameters
+ip=$(get_web_domain_value '$IP')
+web_port=$(get_config_value '$WEB_PORT')
+proxy_port=$(get_config_value '$PROXY_PORT')
+domain=$(get_web_domain_value '$DOMAIN')
+domain_idn=$(idn -t --quiet -a "$domain")
+group="$user"
+docroot="$V_HOME/$user/domains/$domain/public_html"
+email="$user@$domain"
+aliases=$(get_web_domain_value '$ALIAS')
+aliases_idn=$(idn -t --quiet -a "$aliases")
+
+# Checking error log status
+elog=$(get_web_domain_value '$ELOG')
+if [ "$elog" = 'no' ]; then
+    elog=' #'
 else
-    new_alias="$curr_alias,$dom_alias"
+    elog=' '
 fi
 
-# Defining replace string
-str_repl="    ServerAlias ${new_alias//,/ }"
-
-# Adding alias
-httpd_change_config
-
-# Checking ssl domain
-ssl=$(get_web_domain_value '$SSL')
-if [ "$ssl" = 'yes' ]; then
-
-    # Defining ssl template
-    tpl_file="$V_WEBTPL/$package-$tpl_name.ssl.tpl"
-
-    # Defining ssl config
-    conf="$V_HOME/$user/conf/shttpd.conf"
+# Adding domain to the nginx.conf
+tpl_file="$V_WEBTPL/ngingx_vhost_$template.tpl"
+conf="$V_HOME/$user/conf/nginx.conf"
+httpd_add_config
 
-    # Adding alias
-    httpd_change_config
+# Checking vesta nginx config
+main_conf='/etc/nginx/conf.d/vesta_users.conf'
+main_conf_check=$(grep "$conf" $main_conf )
+if [ -z "$main_conf_check" ]; then
+    echo "include $conf;" >>$main_conf
 fi
 
 
@@ -100,13 +92,14 @@ fi
 #                       Vesta                              #
 #----------------------------------------------------------#
 
-# Adding new alias
-update_web_domain_value '$ALIAS' "$new_alias"
+# Adding nginx params to config
+update_web_domain_value '$NGINX' "$template"
+update_web_domain_value '$NGINX_EXT' "$extentions"
 
 # Adding task to the vesta pipe
 restart_schedule 'web'
 
-log_history "$V_EVENT" "v_del_web_domain_alias $user $domain $dom_alias"
+log_history "$V_EVENT" "v_del_web_domain_nginx $user $domain"
 log_event 'system' "$V_EVENT"
 
 exit $OK

+ 2 - 3
data/templates/ngingx_vhost_default.stpl

@@ -16,9 +16,8 @@ server {
         }
     }
 
-    location = /error/ {
-        root    %home%/%user%/domains/%domain%/document_errors/;
-        try_files      $uri @fallback;
+    location /error/ {
+        alias   %home%/%user%/domains/%domain%/document_errors/;
     }
 
     location @fallback {

+ 2 - 3
data/templates/ngingx_vhost_default.tpl

@@ -16,9 +16,8 @@ server {
         }
     }
 
-    location = /error/ {
-        root    %home%/%user%/domains/%domain%/document_errors/;
-        try_files      $uri @fallback;
+    location /error/ {
+        alias   %home%/%user%/domains/%domain%/document_errors/;
     }
 
     location @fallback {