vhost.sh 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
  11. clear
  12. printf "
  13. #######################################################################
  14. # OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+ #
  15. # For more information please visit https://oneinstack.com #
  16. #######################################################################
  17. "
  18. # Check if user is root
  19. [ $(id -u) != '0' ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  20. oneinstack_dir=$(dirname "`readlink -f $0`")
  21. pushd ${oneinstack_dir} > /dev/null
  22. . ./options.conf
  23. . ./include/color.sh
  24. . ./include/check_dir.sh
  25. . ./include/check_os.sh
  26. . ./include/get_char.sh
  27. Show_Help() {
  28. echo
  29. echo "Usage: $0 command ...[parameters]....
  30. --help, -h Show this help message
  31. --quiet, -q quiet operation
  32. --list, -l List Virtualhost
  33. --mphp_ver [53~73] Use another PHP version (PATH: /usr/local/php${mphp_ver})
  34. --add Add Virtualhost
  35. --delete, --del Delete Virtualhost
  36. --httponly Use HTTP Only
  37. --selfsigned Use your own SSL Certificate and Key
  38. --letsencrypt Use Let's Encrypt to Create SSL Certificate and Key
  39. --dnsapi Use dns API to automatically issue Let's Encrypt Cert
  40. "
  41. }
  42. ARG_NUM=$#
  43. TEMP=`getopt -o hql --long help,quiet,list,mphp_ver:,add,delete,del,httponly,selfsigned,letsencrypt,dnsapi -- "$@" 2>/dev/null`
  44. [ $? != 0 ] && echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
  45. eval set -- "${TEMP}"
  46. while :; do
  47. [ -z "$1" ] && break;
  48. case "$1" in
  49. -h|--help)
  50. Show_Help; exit 0
  51. ;;
  52. -q|--quiet)
  53. quiet_flag=y; shift 1
  54. ;;
  55. -l|--list)
  56. list_flag=y; shift 1
  57. ;;
  58. --mphp_ver)
  59. mphp_ver=$2; mphp_flag=y; shift 2
  60. [[ ! "${mphp_ver}" =~ ^5[3-6]$|^7[0-3]$ ]] && { echo "${CWARNING}mphp_ver input error! Please only input number 53~73${CEND}"; unset mphp_ver mphp_flag; }
  61. ;;
  62. --add)
  63. add_flag=y; shift 1
  64. ;;
  65. --delete|--del)
  66. delete_flag=y; shift 1
  67. ;;
  68. --httponly)
  69. sslquiet_flag=y
  70. httponly_flag=y
  71. Domian_Mode=1
  72. shift 1
  73. ;;
  74. --selfsigned)
  75. sslquiet_flag=y
  76. selfsigned_flag=y
  77. Domian_Mode=2
  78. shift 1
  79. ;;
  80. --letsencrypt)
  81. sslquiet_flag=y
  82. letsencrypt_flag=y
  83. Domian_Mode=3
  84. shift 1
  85. ;;
  86. --dnsapi)
  87. sslquiet_flag=y
  88. dnsapi_flag=y
  89. letsencrypt_flag=y
  90. shift 1
  91. ;;
  92. --)
  93. shift
  94. ;;
  95. *)
  96. echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
  97. ;;
  98. esac
  99. done
  100. Choose_ENV() {
  101. if [ -e "${apache_install_dir}/bin/apachectl" ];then
  102. [ "$(${apache_install_dir}/bin/apachectl -v | awk -F'.' /version/'{print $2}')" == '4' ] && { Apache_main_ver=24; Apache_grant='Require all granted'; }
  103. [ "$(${apache_install_dir}/bin/apachectl -v | awk -F'.' /version/'{print $2}')" == '2' ] && Apache_main_ver=22
  104. fi
  105. if [ -e "${php_install_dir}/bin/phpize" -a -e "${tomcat_install_dir}/conf/server.xml" -a -e "/usr/bin/hhvm" ]; then
  106. Number=111
  107. while :; do echo
  108. echo "Please choose to use environment:"
  109. echo -e "\t${CMSG}1${CEND}. Use php"
  110. echo -e "\t${CMSG}2${CEND}. Use java"
  111. echo -e "\t${CMSG}3${CEND}. Use hhvm"
  112. read -e -p "Please input a number:(Default 1 press Enter) " ENV_FLAG
  113. ENV_FLAG=${ENV_FLAG:-1}
  114. if [[ ! ${ENV_FLAG} =~ ^[1-3]$ ]]; then
  115. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  116. else
  117. break
  118. fi
  119. done
  120. case "${ENV_FLAG}" in
  121. 1)
  122. NGX_FLAG=php
  123. ;;
  124. 2)
  125. NGX_FLAG=java
  126. ;;
  127. 3)
  128. NGX_FLAG=hhvm
  129. ;;
  130. esac
  131. elif [ -e "${php_install_dir}/bin/phpize" -a -e "${tomcat_install_dir}/conf/server.xml" -a ! -e "/usr/bin/hhvm" ]; then
  132. Number=110
  133. while :; do echo
  134. echo "Please choose to use environment:"
  135. echo -e "\t${CMSG}1${CEND}. Use php"
  136. echo -e "\t${CMSG}2${CEND}. Use java"
  137. read -e -p "Please input a number:(Default 1 press Enter) " ENV_FLAG
  138. ENV_FLAG=${ENV_FLAG:-1}
  139. if [[ ! ${ENV_FLAG} =~ ^[1-2]$ ]]; then
  140. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  141. else
  142. break
  143. fi
  144. done
  145. [ "${ENV_FLAG}" == '1' ] && NGX_FLAG=php
  146. [ "${ENV_FLAG}" == '2' ] && NGX_FLAG=java
  147. elif [ -e "${php_install_dir}/bin/phpize" -a ! -e "${tomcat_install_dir}/conf/server.xml" -a ! -e "/usr/bin/hhvm" ]; then
  148. Number=100
  149. NGX_FLAG=php
  150. elif [ -e "${php_install_dir}/bin/phpize" -a ! -e "${tomcat_install_dir}/conf/server.xml" -a -e "/usr/bin/hhvm" ]; then
  151. Number=101
  152. while :; do echo
  153. echo "Please choose to use environment:"
  154. echo -e "\t${CMSG}1${CEND}. Use php"
  155. echo -e "\t${CMSG}2${CEND}. Use hhvm"
  156. read -e -p "Please input a number:(Default 1 press Enter) " ENV_FLAG
  157. ENV_FLAG=${ENV_FLAG:-1}
  158. if [[ ! ${ENV_FLAG} =~ ^[1-2]$ ]]; then
  159. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  160. else
  161. break
  162. fi
  163. done
  164. [ "${ENV_FLAG}" == '1' ] && NGX_FLAG=php
  165. [ "${ENV_FLAG}" == '2' ] && NGX_FLAG=hhvm
  166. elif [ ! -e "${php_install_dir}/bin/phpize" -a -e "${tomcat_install_dir}/conf/server.xml" -a -e "/usr/bin/hhvm" ]; then
  167. Number=011
  168. while :; do echo
  169. echo "Please choose to use environment:"
  170. echo -e "\t${CMSG}1${CEND}. Use java"
  171. echo -e "\t${CMSG}2${CEND}. Use hhvm"
  172. read -e -p "Please input a number:(Default 1 press Enter) " ENV_FLAG
  173. ENV_FLAG=${ENV_FLAG:-1}
  174. if [[ ! ${ENV_FLAG} =~ ^[1-2]$ ]]; then
  175. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  176. else
  177. break
  178. fi
  179. done
  180. [ "${ENV_FLAG}" == '1' ] && NGX_FLAG=java
  181. [ "${ENV_FLAG}" == '2' ] && NGX_FLAG=hhvm
  182. elif [ ! -e "${php_install_dir}/bin/phpize" -a -e "${tomcat_install_dir}/conf/server.xml" -a ! -e "/usr/bin/hhvm" ]; then
  183. Number=010
  184. NGX_FLAG=java
  185. elif [ ! -e "${php_install_dir}/bin/phpize" -a ! -e "${tomcat_install_dir}/conf/server.xml" -a -e "/usr/bin/hhvm" ]; then
  186. Number=001
  187. NGX_FLAG=hhvm
  188. else
  189. Number=000
  190. NGX_FLAG=php
  191. fi
  192. }
  193. Create_SSL() {
  194. if [ "${Domian_Mode}" == '2' ]; then
  195. printf "
  196. You are about to be asked to enter information that will be incorporated
  197. into your certificate request.
  198. What you are about to enter is what is called a Distinguished Name or a DN.
  199. There are quite a few fields but you can leave some blank
  200. For some fields there will be a default value,
  201. If you enter '.', the field will be left blank.
  202. "
  203. echo
  204. read -e -p "Country Name (2 letter code) [CN]: " SELFSIGNEDSSL_C
  205. SELFSIGNEDSSL_C=${SELFSIGNEDSSL_C:-CN}
  206. [ ${#SELFSIGNEDSSL_C} != 2 ] && { echo "${CWARNING}input error, You must input 2 letter code country name${CEND}"; continue; }
  207. echo
  208. read -e -p "State or Province Name (full name) [Shanghai]: " SELFSIGNEDSSL_ST
  209. SELFSIGNEDSSL_ST=${SELFSIGNEDSSL_ST:-Shanghai}
  210. echo
  211. read -e -p "Locality Name (eg, city) [Shanghai]: " SELFSIGNEDSSL_L
  212. SELFSIGNEDSSL_L=${SELFSIGNEDSSL_L:-Shanghai}
  213. echo
  214. read -e -p "Organization Name (eg, company) [Example Inc.]: " SELFSIGNEDSSL_O
  215. SELFSIGNEDSSL_O=${SELFSIGNEDSSL_O:-"Example Inc."}
  216. echo
  217. read -e -p "Organizational Unit Name (eg, section) [IT Dept.]: " SELFSIGNEDSSL_OU
  218. SELFSIGNEDSSL_OU=${SELFSIGNEDSSL_OU:-"IT Dept."}
  219. openssl req -utf8 -new -newkey rsa:2048 -sha256 -nodes -out ${PATH_SSL}/${domain}.csr -keyout ${PATH_SSL}/${domain}.key -subj "/C=${SELFSIGNEDSSL_C}/ST=${SELFSIGNEDSSL_ST}/L=${SELFSIGNEDSSL_L}/O=${SELFSIGNEDSSL_O}/OU=${SELFSIGNEDSSL_OU}/CN=${domain}" > /dev/null 2>&1
  220. openssl x509 -req -days 36500 -sha256 -in ${PATH_SSL}/${domain}.csr -signkey ${PATH_SSL}/${domain}.key -out ${PATH_SSL}/${domain}.crt > /dev/null 2>&1
  221. elif [ "${Domian_Mode}" == '3' -o "${dnsapi_flag}" == 'y' ]; then
  222. if [ "${moredomain}" == "*.${domain}" -o "${dnsapi_flag}" == 'y' ]; then
  223. while :; do echo
  224. echo 'Please select DNS provider:'
  225. echo "${CMSG}dp${CEND},${CMSG}cx${CEND},${CMSG}ali${CEND},${CMSG}cf${CEND},${CMSG}aws${CEND},${CMSG}linode${CEND},${CMSG}he${CEND},${CMSG}namesilo${CEND},${CMSG}dgon${CEND},${CMSG}freedns${CEND},${CMSG}gd${CEND},${CMSG}namecom${CEND} and so on."
  226. echo "${CMSG}More: https://oneinstack.com/faq/letsencrypt${CEND}"
  227. read -e -p "Please enter your DNS provider: " DNS_PRO
  228. if [ -e ~/.acme.sh/dnsapi/dns_${DNS_PRO}.sh ]; then
  229. break
  230. else
  231. echo "${CWARNING}You DNS api mode is not supported${CEND}"
  232. fi
  233. done
  234. while :; do echo
  235. echo "Syntax: export Key1=Value1 ; export Key2=Value1"
  236. read -e -p "Please enter your dnsapi parameters: " DNS_PAR
  237. echo
  238. eval ${DNS_PAR}
  239. if [ $? == 0 ]; then
  240. break
  241. else
  242. echo "${CWARNING}Syntax error! PS: export Ali_Key=LTq ; export Ali_Secret=0q5E${CEND}"
  243. fi
  244. done
  245. [ "${moredomainame_flag}" == 'y' ] && moredomainame_D="$(for D in ${moredomainame}; do echo -d ${D}; done)"
  246. ~/.acme.sh/acme.sh --issue --dns dns_${DNS_PRO} -d ${domain} ${moredomainame_D}
  247. else
  248. if [ "${nginx_ssl_flag}" == 'y' ]; then
  249. [ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
  250. echo "server { server_name ${domain}${moredomainame}; root ${vhostdir}; access_log off; }" > ${web_install_dir}/conf/vhost/${domain}.conf
  251. ${web_install_dir}/sbin/nginx -s reload
  252. fi
  253. if [ "${apache_ssl_flag}" == 'y' ]; then
  254. [ ! -d ${apache_install_dir}/conf/vhost ] && mkdir ${apache_install_dir}/conf/vhost
  255. cat > ${apache_install_dir}/conf/vhost/${domain}.conf << EOF
  256. <VirtualHost *:80>
  257. ServerAdmin admin@example.com
  258. DocumentRoot "${vhostdir}"
  259. ServerName ${domain}
  260. ${Apache_Domain_alias}
  261. <Directory "${vhostdir}">
  262. SetOutputFilter DEFLATE
  263. Options FollowSymLinks ExecCGI
  264. ${Apache_grant}
  265. AllowOverride All
  266. Order allow,deny
  267. Allow from all
  268. DirectoryIndex index.html index.php
  269. </Directory>
  270. </VirtualHost>
  271. EOF
  272. ${apache_install_dir}/bin/apachectl -k graceful
  273. fi
  274. auth_file="`< /dev/urandom tr -dc A-Za-z0-9 | head -c8`".html
  275. auth_str='oneinstack'; echo ${auth_str} > ${vhostdir}/${auth_file}
  276. for D in ${domain} ${moredomainame}
  277. do
  278. curl_str=`curl --connect-timeout 30 -4 -s $D/${auth_file} 2>&1`
  279. [ "${curl_str}" != "${auth_str}" ] && { echo; echo "${CFAILURE}Let's Encrypt Verify error! DNS problem: NXDOMAIN looking up A for ${D}${CEND}"; }
  280. done
  281. rm -f ${vhostdir}/${auth_file}
  282. [ "${moredomainame_flag}" == 'y' ] && moredomainame_D="$(for D in ${moredomainame}; do echo -d ${D}; done)"
  283. ~/.acme.sh/acme.sh --issue -d ${domain} ${moredomainame_D} -w ${vhostdir}
  284. fi
  285. if [ -s ~/.acme.sh/${domain}/fullchain.cer ]; then
  286. [ -e "${PATH_SSL}/${domain}.crt" ] && rm -f ${PATH_SSL}/${domain}.{crt,key}
  287. [ -e /bin/systemctl -a -e /lib/systemd/system/nginx.service ] && Nginx_cmd='/bin/systemctl restart nginx' || Nginx_cmd='/etc/init.d/nginx force-reload'
  288. Apache_cmd="${apache_install_dir}/bin/apachectl -k graceful"
  289. if [ -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  290. Command="${Nginx_cmd};${Apache_cmd}"
  291. elif [ -e "${web_install_dir}/sbin/nginx" -a ! -e "${apache_install_dir}/bin/httpd" ]; then
  292. Command="${Nginx_cmd}"
  293. elif [ ! -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  294. Command="${Apache_cmd}"
  295. fi
  296. ~/.acme.sh/acme.sh --install-cert -d ${domain} --fullchain-file ${PATH_SSL}/${domain}.crt --key-file ${PATH_SSL}/${domain}.key --reloadcmd "${Command}" > /dev/null
  297. else
  298. echo "${CFAILURE}Error: Create Let's Encrypt SSL Certificate failed! ${CEND}"
  299. [ -e "${web_install_dir}/conf/vhost/${domain}.conf" ] && rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  300. [ -e "${apache_install_dir}/conf/vhost/${domain}.conf" ] && rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  301. exit 1
  302. fi
  303. fi
  304. }
  305. Print_SSL() {
  306. if [ "${Domian_Mode}" == '2' ]; then
  307. echo "$(printf "%-30s" "Self-signed SSL Certificate:")${CMSG}${PATH_SSL}/${domain}.crt${CEND}"
  308. echo "$(printf "%-30s" "SSL Private Key:")${CMSG}${PATH_SSL}/${domain}.key${CEND}"
  309. echo "$(printf "%-30s" "SSL CSR File:")${CMSG}${PATH_SSL}/${domain}.csr${CEND}"
  310. elif [ "${Domian_Mode}" == '3' -o "${dnsapi_flag}" == 'y' ]; then
  311. echo "$(printf "%-30s" "Let's Encrypt SSL Certificate:")${CMSG}${PATH_SSL}/${domain}.crt${CEND}"
  312. echo "$(printf "%-30s" "SSL Private Key:")${CMSG}${PATH_SSL}/${domain}.key${CEND}"
  313. fi
  314. }
  315. Input_Add_domain() {
  316. if [ "${sslquiet_flag}" != 'y' ]; then
  317. while :;do
  318. printf "
  319. What Are You Doing?
  320. \t${CMSG}1${CEND}. Use HTTP Only
  321. \t${CMSG}2${CEND}. Use your own SSL Certificate and Key
  322. \t${CMSG}3${CEND}. Use Let's Encrypt to Create SSL Certificate and Key
  323. \t${CMSG}q${CEND}. Exit
  324. "
  325. read -e -p "Please input the correct option: " Domian_Mode
  326. if [[ ! "${Domian_Mode}" =~ ^[1-3,q]$ ]]; then
  327. echo "${CFAILURE}input error! Please only input 1~3 and q${CEND}"
  328. else
  329. break
  330. fi
  331. done
  332. fi
  333. #Multiple_PHP
  334. if [ $(ls /dev/shm/php*-cgi.sock 2> /dev/null | wc -l) -ge 2 ]; then
  335. if [ "${mphp_flag}" != 'y' ]; then
  336. PHP_detail_ver=`${php_install_dir}/bin/php-config --version`
  337. PHP_main_ver=${PHP_detail_ver%.*}
  338. while :; do echo
  339. echo 'Please select a version of the PHP:'
  340. echo -e "\t${CMSG}1${CEND}. PHP ${PHP_main_ver} (default)"
  341. [ -e "/dev/shm/php53-cgi.sock" ] && echo -e "\t${CMSG}2${CEND}. PHP 5.3"
  342. [ -e "/dev/shm/php54-cgi.sock" ] && echo -e "\t${CMSG}3${CEND}. PHP 5.4"
  343. [ -e "/dev/shm/php55-cgi.sock" ] && echo -e "\t${CMSG}4${CEND}. PHP 5.5"
  344. [ -e "/dev/shm/php56-cgi.sock" ] && echo -e "\t${CMSG}5${CEND}. PHP 5.6"
  345. [ -e "/dev/shm/php70-cgi.sock" ] && echo -e "\t${CMSG}6${CEND}. PHP 7.0"
  346. [ -e "/dev/shm/php71-cgi.sock" ] && echo -e "\t${CMSG}7${CEND}. PHP 7.1"
  347. [ -e "/dev/shm/php72-cgi.sock" ] && echo -e "\t${CMSG}8${CEND}. PHP 7.2"
  348. [ -e "/dev/shm/php73-cgi.sock" ] && echo -e "\t${CMSG}9${CEND}. PHP 7.3"
  349. read -e -p "Please input a number:(Default 1 press Enter) " php_option
  350. php_option=${php_option:-1}
  351. if [[ ! ${php_option} =~ ^[1-9]$ ]]; then
  352. echo "${CWARNING}input error! Please only input number 1~9${CEND}"
  353. else
  354. break
  355. fi
  356. done
  357. fi
  358. [ "${php_option}" == '2' ] && mphp_ver=53
  359. [ "${php_option}" == '3' ] && mphp_ver=54
  360. [ "${php_option}" == '4' ] && mphp_ver=55
  361. [ "${php_option}" == '5' ] && mphp_ver=56
  362. [ "${php_option}" == '6' ] && mphp_ver=70
  363. [ "${php_option}" == '7' ] && mphp_ver=71
  364. [ "${php_option}" == '8' ] && mphp_ver=72
  365. [ "${php_option}" == '9' ] && mphp_ver=73
  366. [ ! -e "/dev/shm/php${mphp_ver}-cgi.sock" ] && unset mphp_ver
  367. fi
  368. case "${NGX_FLAG}" in
  369. "php")
  370. NGX_CONF=$(echo -e "location ~ [^/]\.php(/|$) {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n }")
  371. ;;
  372. "java")
  373. NGX_CONF=$(echo -e "location ~ {\n proxy_pass http://127.0.0.1:8080;\n include proxy.conf;\n }")
  374. ;;
  375. "hhvm")
  376. NGX_CONF=$(echo -e "location ~ .*\.(php|php5)?$ {\n fastcgi_pass unix:/var/log/hhvm/sock;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;\n include fastcgi_params;\n }")
  377. ;;
  378. esac
  379. if [ "${Domian_Mode}" == '3' -o "${dnsapi_flag}" == 'y' ] && [ ! -e ~/.acme.sh/acme.sh ]; then
  380. pushd ${oneinstack_dir}/src > /dev/null
  381. [ ! -e acme.sh-master.tar.gz ] && wget -qc http://mirrors.linuxeye.com/oneinstack/src/acme.sh-master.tar.gz
  382. tar xzf acme.sh-master.tar.gz
  383. pushd acme.sh-master > /dev/null
  384. ./acme.sh --install > /dev/null 2>&1
  385. popd > /dev/null
  386. popd > /dev/null
  387. fi
  388. [ -e ~/.acme.sh/account.conf ] && sed -i '/^CERT_HOME=/d' ~/.acme.sh/account.conf
  389. if [[ "${Domian_Mode}" =~ ^[2-3]$ ]] || [ "${dnsapi_flag}" == 'y' ]; then
  390. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  391. nginx_ssl_flag=y
  392. PATH_SSL=${web_install_dir}/conf/ssl
  393. [ ! -d "${PATH_SSL}" ] && mkdir ${PATH_SSL}
  394. elif [ ! -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  395. apache_ssl_flag=y
  396. PATH_SSL=${apache_install_dir}/conf/ssl
  397. [ ! -d "${PATH_SSL}" ] && mkdir ${PATH_SSL}
  398. fi
  399. elif [ "${Domian_Mode}" == 'q' ]; then
  400. exit 1
  401. fi
  402. while :; do echo
  403. read -e -p "Please input domain(example: www.example.com): " domain
  404. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  405. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  406. else
  407. break
  408. fi
  409. done
  410. if [ -e "${web_install_dir}/conf/vhost/${domain}.conf" -o -e "${apache_install_dir}/conf/vhost/${domain}.conf" -o -e "${tomcat_install_dir}/conf/vhost/${domain}.xml" ]; then
  411. [ -e "${web_install_dir}/conf/vhost/${domain}.conf" ] && echo -e "${domain} in the Nginx/Tengine/OpenResty already exist! \nYou can delete ${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND} and re-create"
  412. [ -e "${apache_install_dir}/conf/vhost/${domain}.conf" ] && echo -e "${domain} in the Apache already exist! \nYou can delete ${CMSG}${apache_install_dir}/conf/vhost/${domain}.conf${CEND} and re-create"
  413. [ -e "${tomcat_install_dir}/conf/vhost/${domain}.xml" ] && echo -e "${domain} in the Tomcat already exist! \nYou can delete ${CMSG}${tomcat_install_dir}/conf/vhost/${domain}.xml${CEND} and re-create"
  414. exit
  415. else
  416. echo "domain=${domain}"
  417. fi
  418. while :; do echo
  419. echo "Please input the directory for the domain:${domain} :"
  420. read -e -p "(Default directory: ${wwwroot_dir}/${domain}): " vhostdir
  421. if [ -n "${vhostdir}" -a -z "$(echo ${vhostdir} | grep '^/')" ]; then
  422. echo "${CWARNING}input error! Press Enter to continue...${CEND}"
  423. else
  424. if [ -z "${vhostdir}" ]; then
  425. vhostdir="${wwwroot_dir}/${domain}"
  426. echo "Virtual Host Directory=${CMSG}${vhostdir}${CEND}"
  427. fi
  428. echo
  429. echo "Create Virtul Host directory......"
  430. mkdir -p ${vhostdir}
  431. echo "set permissions of Virtual Host directory......"
  432. chown -R ${run_user}.${run_user} ${vhostdir}
  433. break
  434. fi
  435. done
  436. while :; do echo
  437. read -e -p "Do you want to add more domain name? [y/n]: " moredomainame_flag
  438. if [[ ! ${moredomainame_flag} =~ ^[y,n]$ ]]; then
  439. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  440. else
  441. break
  442. fi
  443. done
  444. if [ "${moredomainame_flag}" == 'y' ]; then
  445. while :; do echo
  446. read -e -p "Type domainname or IP(example: example.com other.example.com): " moredomain
  447. if [ -z "$(echo ${moredomain} | grep '.*\..*')" ]; then
  448. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  449. else
  450. [ "${moredomain}" == "${domain}" ] && echo "${CWARNING}Domain name already exists! ${CND}" && continue
  451. echo domain list="$moredomain"
  452. moredomainame=" $moredomain"
  453. break
  454. fi
  455. done
  456. Apache_Domain_alias=ServerAlias${moredomainame}
  457. Tomcat_Domain_alias=$(for D in $(echo ${moredomainame}); do echo "<Alias>${D}</Alias>"; done)
  458. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  459. while :; do echo
  460. read -e -p "Do you want to redirect from ${moredomain} to ${domain}? [y/n]: " redirect_flag
  461. if [[ ! ${redirect_flag} =~ ^[y,n]$ ]]; then
  462. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  463. else
  464. break
  465. fi
  466. done
  467. [ "${redirect_flag}" == 'y' ] && Nginx_redirect="if (\$host != ${domain}) { return 301 \$scheme://${domain}\$request_uri; }"
  468. fi
  469. fi
  470. if [ "${nginx_ssl_flag}" == 'y' ]; then
  471. while :; do echo
  472. read -e -p "Do you want to redirect all HTTP requests to HTTPS? [y/n]: " https_flag
  473. if [[ ! ${https_flag} =~ ^[y,n]$ ]]; then
  474. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  475. else
  476. break
  477. fi
  478. done
  479. if [[ "$(${web_install_dir}/sbin/nginx -V 2>&1 | grep -Eo 'with-http_v2_module')" = 'with-http_v2_module' ]]; then
  480. LISTENOPT="443 ssl http2"
  481. else
  482. LISTENOPT="443 ssl spdy"
  483. fi
  484. Create_SSL
  485. Nginx_conf=$(echo -e "listen 80;\n listen ${LISTENOPT};\n ssl_certificate ${PATH_SSL}/${domain}.crt;\n ssl_certificate_key ${PATH_SSL}/${domain}.key;\n ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;\n ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;\n ssl_prefer_server_ciphers on;\n ssl_session_timeout 10m;\n ssl_session_cache builtin:1000 shared:SSL:10m;\n ssl_buffer_size 1400;\n add_header Strict-Transport-Security max-age=15768000;\n ssl_stapling on;\n ssl_stapling_verify on;\n")
  486. Apache_SSL=$(echo -e "SSLEngine on\n SSLCertificateFile \"${PATH_SSL}/${domain}.crt\"\n SSLCertificateKeyFile \"${PATH_SSL}/${domain}.key\"")
  487. elif [ "$apache_ssl_flag" == 'y' ]; then
  488. Create_SSL
  489. Apache_SSL=$(echo -e "SSLEngine on\n SSLCertificateFile \"${PATH_SSL}/${domain}.crt\"\n SSLCertificateKeyFile \"${PATH_SSL}/${domain}.key\"")
  490. [ -z "$(grep 'Listen 443' ${apache_install_dir}/conf/httpd.conf)" ] && sed -i "s@Listen 80@&\nListen 443@" ${apache_install_dir}/conf/httpd.conf
  491. [ -z "$(grep 'ServerName 0.0.0.0:443' ${apache_install_dir}/conf/httpd.conf)" ] && sed -i "s@ServerName 0.0.0.0:80@&\nServerName 0.0.0.0:443@" ${apache_install_dir}/conf/httpd.conf
  492. else
  493. Nginx_conf="listen 80;"
  494. fi
  495. }
  496. Nginx_anti_hotlinking() {
  497. while :; do echo
  498. read -e -p "Do you want to add hotlink protection? [y/n]: " anti_hotlinking_flag
  499. if [[ ! ${anti_hotlinking_flag} =~ ^[y,n]$ ]]; then
  500. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  501. else
  502. break
  503. fi
  504. done
  505. if [ -n "$(echo ${domain} | grep '.*\..*\..*')" ]; then
  506. domain_allow="*.${domain#*.} ${domain}"
  507. else
  508. domain_allow="*.${domain} ${domain}"
  509. fi
  510. if [ "${anti_hotlinking_flag}" == 'y' ]; then
  511. if [ "${moredomainame_flag}" == 'y' -a "${moredomain}" != "*.${domain}" ]; then
  512. domain_allow_all=${domain_allow}${moredomainame}
  513. else
  514. domain_allow_all=${domain_allow}
  515. fi
  516. domain_allow_all=`echo ${domain_allow_all} | tr ' ' '\n' | awk '!a[$1]++' | xargs`
  517. anti_hotlinking=$(echo -e "location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)$ {\n valid_referers none blocked ${domain_allow_all};\n if (\$invalid_referer) {\n return 403;\n }\n }")
  518. fi
  519. }
  520. Nginx_rewrite() {
  521. [ ! -d "${web_install_dir}/conf/rewrite" ] && mkdir ${web_install_dir}/conf/rewrite
  522. while :; do echo
  523. read -e -p "Allow Rewrite rule? [y/n]: " rewrite_flag
  524. if [[ ! "${rewrite_flag}" =~ ^[y,n]$ ]]; then
  525. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  526. else
  527. break
  528. fi
  529. done
  530. if [ "${rewrite_flag}" == 'n' ]; then
  531. rewrite="none"
  532. touch "${web_install_dir}/conf/rewrite/${rewrite}.conf"
  533. else
  534. echo
  535. echo "Please input the rewrite of programme :"
  536. echo "${CMSG}wordpress${CEND},${CMSG}opencart${CEND},${CMSG}magento2${CEND},${CMSG}drupal${CEND},${CMSG}joomla${CEND},${CMSG}codeigniter${CEND},${CMSG}laravel${CEND}"
  537. echo "${CMSG}thinkphp${CEND},${CMSG}pathinfo${CEND},${CMSG}discuz${CEND},${CMSG}typecho${CEND},${CMSG}ecshop${CEND},${CMSG}nextcloud${CEND},${CMSG}zblog${CEND} rewrite was exist."
  538. read -e -p "(Default rewrite: other): " rewrite
  539. if [ "${rewrite}" == "" ]; then
  540. rewrite="other"
  541. fi
  542. echo "You choose rewrite=${CMSG}$rewrite${CEND}"
  543. [ "${NGX_FLAG}" == 'php' -a "${rewrite}" == "joomla" ] && NGX_CONF=$(echo -e "location ~ \\.php\$ {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n }")
  544. #[ "${NGX_FLAG}" == 'php' ] && [[ "${rewrite}" =~ ^codeigniter$|^thinkphp$|^pathinfo$ ]] && NGX_CONF=$(echo -e "location ~ [^/]\.php(/|\$) {\n try_files \$uri =404;\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n set \$real_script_name \$fastcgi_script_name;\n if (\$fastcgi_script_name ~ \"^(.+?\.php)(/.+)\$\") {\n set \$real_script_name \$1;\n set \$path_info \$2;\n }\n fastcgi_param SCRIPT_FILENAME \$document_root\$real_script_name;\n fastcgi_param SCRIPT_NAME \$real_script_name;\n fastcgi_param PATH_INFO \$path_info;\n }")
  545. [ "${NGX_FLAG}" == 'php' ] && [[ "${rewrite}" =~ ^codeigniter$|^thinkphp$|^pathinfo$ ]] && NGX_CONF=$(echo -e "location ~ [^/]\.php(/|\$) {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n fastcgi_split_path_info ^(.+?\.php)(/.*)\$;\n set \$path_info \$fastcgi_path_info;\n fastcgi_param PATH_INFO \$path_info;\n try_files \$fastcgi_script_name =404; \n }")
  546. [ "${NGX_FLAG}" == 'php' -a "${rewrite}" == "typecho" ] && NGX_CONF=$(echo -e "location ~ .*\.php(\/.*)*\$ {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n set \$path_info \"\";\n set \$real_script_name \$fastcgi_script_name;\n if (\$fastcgi_script_name ~ \"^(.+?\.php)(/.+)\$\") {\n set \$real_script_name \$1;\n set \$path_info \$2;\n }\n fastcgi_param SCRIPT_FILENAME \$document_root\$real_script_name;\n fastcgi_param SCRIPT_NAME \$real_script_name;\n fastcgi_param PATH_INFO \$path_info;\n }")
  547. if [[ ! "${rewrite}" =~ ^magento2$|^pathinfo$ ]]; then
  548. if [ -e "config/${rewrite}.conf" ]; then
  549. /bin/cp config/${rewrite}.conf ${web_install_dir}/conf/rewrite/${rewrite}.conf
  550. else
  551. touch "${web_install_dir}/conf/rewrite/${rewrite}.conf"
  552. fi
  553. fi
  554. fi
  555. }
  556. Nginx_log() {
  557. while :; do echo
  558. read -e -p "Allow Nginx/Tengine/OpenResty access_log? [y/n]: " access_flag
  559. if [[ ! "${access_flag}" =~ ^[y,n]$ ]]; then
  560. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  561. else
  562. break
  563. fi
  564. done
  565. if [ "${access_flag}" == 'n' ]; then
  566. Nginx_log="access_log off;"
  567. else
  568. Nginx_log="access_log ${wwwlogs_dir}/${domain}_nginx.log combined;"
  569. echo "You access log file=${CMSG}${wwwlogs_dir}/${domain}_nginx.log${CEND}"
  570. fi
  571. }
  572. Create_nginx_tomcat_conf() {
  573. [ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
  574. cat > ${web_install_dir}/conf/vhost/${domain}.conf << EOF
  575. server {
  576. ${Nginx_conf}
  577. server_name ${domain}${moredomainame};
  578. ${Nginx_log}
  579. index index.html index.htm index.jsp;
  580. root ${vhostdir};
  581. ${Nginx_redirect}
  582. #error_page 404 /404.html;
  583. #error_page 502 /502.html;
  584. ${anti_hotlinking}
  585. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
  586. expires 30d;
  587. access_log off;
  588. }
  589. location ~ .*\.(js|css)?$ {
  590. expires 7d;
  591. access_log off;
  592. }
  593. location ~ /\.ht {
  594. deny all;
  595. }
  596. ${NGX_CONF}
  597. }
  598. EOF
  599. [ "${https_flag}" == 'y' ] && sed -i "s@^root.*;@&\nif (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  600. cat > ${tomcat_install_dir}/conf/vhost/${domain}.xml << EOF
  601. <Host name="${domain}" appBase="${vhostdir}" unpackWARs="true" autoDeploy="true"> ${Tomcat_Domain_alias}
  602. <Context path="" docBase="${vhostdir}" reloadable="false" crossContext="true"/>
  603. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  604. prefix="${domain}_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  605. <Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For"
  606. protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https"/>
  607. </Host>
  608. EOF
  609. [ -z "$(grep -o "vhost-${domain} SYSTEM" ${tomcat_install_dir}/conf/server.xml)" ] && sed -i "/vhost-localhost SYSTEM/a<\!ENTITY vhost-${domain} SYSTEM \"file://${tomcat_install_dir}/conf/vhost/${domain}.xml\">" ${tomcat_install_dir}/conf/server.xml
  610. [ -z "$(grep -o "vhost-${domain};" ${tomcat_install_dir}/conf/server.xml)" ] && sed -i "s@vhost-localhost;@&\n \&vhost-${domain};@" ${tomcat_install_dir}/conf/server.xml
  611. echo
  612. ${web_install_dir}/sbin/nginx -t
  613. if [ $? == 0 ]; then
  614. echo "Reload Nginx......"
  615. ${web_install_dir}/sbin/nginx -s reload
  616. service tomcat restart
  617. else
  618. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  619. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  620. exit 1
  621. fi
  622. printf "
  623. #######################################################################
  624. # OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+ #
  625. # For more information please visit https://oneinstack.com #
  626. #######################################################################
  627. "
  628. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  629. echo "$(printf "%-30s" "Nginx Virtualhost conf:")${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND}"
  630. echo "$(printf "%-30s" "Tomcat Virtualhost conf:")${CMSG}${tomcat_install_dir}/conf/vhost/${domain}.xml${CEND}"
  631. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  632. Print_SSL
  633. }
  634. Create_tomcat_conf() {
  635. cat > ${tomcat_install_dir}/conf/vhost/${domain}.xml << EOF
  636. <Host name="${domain}" appBase="webapps" unpackWARs="true" autoDeploy="true"> ${Tomcat_Domain_alias}
  637. <Context path="" docBase="${vhostdir}" reloadable="false" crossContext="true"/>
  638. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  639. prefix="${domain}_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  640. </Host>
  641. EOF
  642. [ -z "$(grep -o "vhost-${domain} SYSTEM" ${tomcat_install_dir}/conf/server.xml)" ] && sed -i "/vhost-localhost SYSTEM/a<\!ENTITY vhost-${domain} SYSTEM \"file://${tomcat_install_dir}/conf/vhost/${domain}.xml\">" ${tomcat_install_dir}/conf/server.xml
  643. [ -z "$(grep -o "vhost-${domain};" ${tomcat_install_dir}/conf/server.xml)" ] && sed -i "s@vhost-localhost;@&\n \&vhost-${domain};@" ${tomcat_install_dir}/conf/server.xml
  644. echo
  645. service tomcat restart
  646. printf "
  647. #######################################################################
  648. # OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+ #
  649. # For more information please visit https://oneinstack.com #
  650. #######################################################################
  651. "
  652. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  653. echo "$(printf "%-30s" "Tomcat Virtualhost conf:")${CMSG}${tomcat_install_dir}/conf/vhost/${domain}.xml${CEND}"
  654. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  655. echo "$(printf "%-30s" "index url:")${CMSG}http://${domain}:8080/${CEND}"
  656. }
  657. Create_nginx_phpfpm_hhvm_conf() {
  658. [ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
  659. cat > ${web_install_dir}/conf/vhost/${domain}.conf << EOF
  660. server {
  661. ${Nginx_conf}
  662. server_name ${domain}${moredomainame};
  663. ${Nginx_log}
  664. index index.html index.htm index.php;
  665. root ${vhostdir};
  666. ${Nginx_redirect}
  667. include ${web_install_dir}/conf/rewrite/${rewrite}.conf;
  668. #error_page 404 /404.html;
  669. #error_page 502 /502.html;
  670. ${anti_hotlinking}
  671. ${NGX_CONF}
  672. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
  673. expires 30d;
  674. access_log off;
  675. }
  676. location ~ .*\.(js|css)?$ {
  677. expires 7d;
  678. access_log off;
  679. }
  680. location ~ /\.ht {
  681. deny all;
  682. }
  683. }
  684. EOF
  685. [ "${rewrite}" == 'pathinfo' ] && sed -i '/pathinfo.conf;$/d' ${web_install_dir}/conf/vhost/${domain}.conf
  686. if [ "${rewrite}" == 'magento2' -a -e "config/${rewrite}.conf" ]; then
  687. /bin/cp config/${rewrite}.conf ${web_install_dir}/conf/vhost/${domain}.conf
  688. sed -i "s@/dev/shm/php-cgi.sock@/dev/shm/php${mphp_ver}-cgi.sock@g" ${web_install_dir}/conf/vhost/${domain}.conf
  689. sed -i "s@^ set \$MAGE_ROOT.*;@ set \$MAGE_ROOT ${vhostdir};@" ${web_install_dir}/conf/vhost/${domain}.conf
  690. sed -i "s@^ server_name.*;@ server_name ${domain}${moredomainame};@" ${web_install_dir}/conf/vhost/${domain}.conf
  691. sed -i "s@^ server_name.*;@&\n ${Nginx_log}@" ${web_install_dir}/conf/vhost/${domain}.conf
  692. [ "${NGX_FLAG}" == 'hhvm' ] && sed -i 's@fastcgi_pass unix:.*;@fastcgi_pass unix:/var/log/hhvm/sock;@g' ${web_install_dir}/conf/vhost/${domain}.conf
  693. if [ "${anti_hotlinking_flag}" == 'y' ]; then
  694. sed -i "s@^ root.*;@&\n }@" ${web_install_dir}/conf/vhost/${domain}.conf
  695. sed -i "s@^ root.*;@&\n }@" ${web_install_dir}/conf/vhost/${domain}.conf
  696. sed -i "s@^ root.*;@&\n return 403;@" ${web_install_dir}/conf/vhost/${domain}.conf
  697. sed -i "s@^ root.*;@&\n rewrite ^/ http://www.linuxeye.com/403.html;@" ${web_install_dir}/conf/vhost/${domain}.conf
  698. sed -i "s@^ root.*;@&\n if (\$invalid_referer) {@" ${web_install_dir}/conf/vhost/${domain}.conf
  699. sed -i "s@^ root.*;@&\n valid_referers none blocked ${domain_allow_all};@" ${web_install_dir}/conf/vhost/${domain}.conf
  700. sed -i "s@^ root.*;@&\n location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)\$ {@" ${web_install_dir}/conf/vhost/${domain}.conf
  701. fi
  702. [ "${redirect_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$host != ${domain}) { return 301 \$scheme://${domain}\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  703. if [ "${nginx_ssl_flag}" == 'y' ]; then
  704. sed -i "s@^ listen 80;@&\n listen ${LISTENOPT};@" ${web_install_dir}/conf/vhost/${domain}.conf
  705. sed -i "s@^ server_name.*;@&\n ssl_stapling_verify on;@" ${web_install_dir}/conf/vhost/${domain}.conf
  706. sed -i "s@^ server_name.*;@&\n ssl_stapling on;@" ${web_install_dir}/conf/vhost/${domain}.conf
  707. sed -i "s@^ server_name.*;@&\n add_header Strict-Transport-Security max-age=15768000;@" ${web_install_dir}/conf/vhost/${domain}.conf
  708. sed -i "s@^ server_name.*;@&\n ssl_buffer_size 1400;@" ${web_install_dir}/conf/vhost/${domain}.conf
  709. sed -i "s@^ server_name.*;@&\n ssl_session_cache builtin:1000 shared:SSL:10m;@" ${web_install_dir}/conf/vhost/${domain}.conf
  710. sed -i "s@^ server_name.*;@&\n ssl_session_timeout 10m;@" ${web_install_dir}/conf/vhost/${domain}.conf
  711. sed -i "s@^ server_name.*;@&\n ssl_prefer_server_ciphers on;@" ${web_install_dir}/conf/vhost/${domain}.conf
  712. sed -i "s@^ server_name.*;@&\n ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:\!MD5;@" ${web_install_dir}/conf/vhost/${domain}.conf
  713. sed -i "s@^ server_name.*;@&\n ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;@" ${web_install_dir}/conf/vhost/${domain}.conf
  714. sed -i "s@^ server_name.*;@&\n ssl_certificate_key ${PATH_SSL}/${domain}.key;@" ${web_install_dir}/conf/vhost/${domain}.conf
  715. sed -i "s@^ server_name.*;@&\n ssl_certificate ${PATH_SSL}/${domain}.crt;@" ${web_install_dir}/conf/vhost/${domain}.conf
  716. fi
  717. fi
  718. [ "${https_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  719. echo
  720. ${web_install_dir}/sbin/nginx -t
  721. if [ $? == 0 ]; then
  722. echo "Reload Nginx......"
  723. ${web_install_dir}/sbin/nginx -s reload
  724. else
  725. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  726. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  727. exit 1
  728. fi
  729. printf "
  730. #######################################################################
  731. # OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+ #
  732. # For more information please visit https://oneinstack.com #
  733. #######################################################################
  734. "
  735. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  736. echo "$(printf "%-30s" "Virtualhost conf:")${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND}"
  737. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  738. [ "${rewrite_flag}" == 'y' -a "${rewrite}" != 'magento2' -a "${rewrite}" != 'pathinfo' ] && echo "$(printf "%-30s" "Rewrite rule:")${CMSG}${web_install_dir}/conf/rewrite/${rewrite}.conf${CEND}"
  739. Print_SSL
  740. }
  741. Apache_log() {
  742. while :; do echo
  743. read -e -p "Allow Apache access_log? [y/n]: " access_flag
  744. if [[ ! "${access_flag}" =~ ^[y,n]$ ]]; then
  745. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  746. else
  747. break
  748. fi
  749. done
  750. if [ "${access_flag}" == 'n' ]; then
  751. Apache_log='CustomLog "/dev/null" common'
  752. else
  753. Apache_log="CustomLog \"${wwwlogs_dir}/${domain}_apache.log\" common"
  754. echo "You access log file=${wwwlogs_dir}/${domain}_apache.log"
  755. fi
  756. }
  757. Create_apache_conf() {
  758. if [ "${Apache_main_ver}" == '24' ]; then
  759. if [ -e "${php_install_dir}/sbin/php-fpm" ] && [ -n "`grep -E ^LoadModule.*mod_proxy_fcgi.so ${apache_install_dir}/conf/httpd.conf`" ]; then
  760. Apache_fcgi=$(echo -e "<Files ~ (\\.user.ini|\\.htaccess|\\.git|\\.svn|\\.project|LICENSE|README.md)\$>\n Order allow,deny\n Deny from all\n </Files>\n <FilesMatch \\.php\$>\n SetHandler \"proxy:unix:/dev/shm/php${mphp_ver}-cgi.sock|fcgi://localhost\"\n </FilesMatch>")
  761. fi
  762. fi
  763. [ ! -d ${apache_install_dir}/conf/vhost ] && mkdir ${apache_install_dir}/conf/vhost
  764. cat > ${apache_install_dir}/conf/vhost/${domain}.conf << EOF
  765. <VirtualHost *:80>
  766. ServerAdmin admin@example.com
  767. DocumentRoot "${vhostdir}"
  768. ServerName ${domain}
  769. ${Apache_Domain_alias}
  770. ErrorLog "${wwwlogs_dir}/${domain}_error_apache.log"
  771. ${Apache_log}
  772. ${Apache_fcgi}
  773. <Directory "${vhostdir}">
  774. SetOutputFilter DEFLATE
  775. Options FollowSymLinks ExecCGI
  776. ${Apache_grant}
  777. AllowOverride All
  778. Order allow,deny
  779. Allow from all
  780. DirectoryIndex index.html index.php
  781. </Directory>
  782. </VirtualHost>
  783. EOF
  784. [ "$apache_ssl_flag" == 'y' ] && cat >> ${apache_install_dir}/conf/vhost/${domain}.conf << EOF
  785. <VirtualHost *:443>
  786. ServerAdmin admin@example.com
  787. DocumentRoot "${vhostdir}"
  788. ServerName ${domain}
  789. ${Apache_Domain_alias}
  790. ${Apache_SSL}
  791. ErrorLog "${wwwlogs_dir}/${domain}_error_apache.log"
  792. ${Apache_log}
  793. ${Apache_fcgi}
  794. <Directory "${vhostdir}">
  795. SetOutputFilter DEFLATE
  796. Options FollowSymLinks ExecCGI
  797. ${Apache_grant}
  798. AllowOverride All
  799. Order allow,deny
  800. Allow from all
  801. DirectoryIndex index.html index.php
  802. </Directory>
  803. </VirtualHost>
  804. EOF
  805. echo
  806. ${apache_install_dir}/bin/apachectl -t
  807. if [ $? == 0 ]; then
  808. echo "Restart Apache......"
  809. ${apache_install_dir}/bin/apachectl -k graceful
  810. else
  811. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  812. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  813. exit 1
  814. fi
  815. printf "
  816. #######################################################################
  817. # OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+ #
  818. # For more information please visit https://oneinstack.com #
  819. #######################################################################
  820. "
  821. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  822. echo "$(printf "%-30s" "Virtualhost conf:")${CMSG}${apache_install_dir}/conf/vhost/${domain}.conf${CEND}"
  823. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  824. Print_SSL
  825. }
  826. Create_nginx_apache_modphp_conf() {
  827. # Nginx/Tengine/OpenResty
  828. [ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
  829. cat > ${web_install_dir}/conf/vhost/${domain}.conf << EOF
  830. server {
  831. ${Nginx_conf}
  832. server_name ${domain}${moredomainame};
  833. ${Nginx_log}
  834. index index.html index.htm index.php;
  835. root ${vhostdir};
  836. ${Nginx_redirect}
  837. ${anti_hotlinking}
  838. location / {
  839. try_files \$uri @apache;
  840. }
  841. location @apache {
  842. proxy_pass http://127.0.0.1:88;
  843. include proxy.conf;
  844. }
  845. location ~ .*\.(php|php5|cgi|pl)?$ {
  846. proxy_pass http://127.0.0.1:88;
  847. include proxy.conf;
  848. }
  849. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
  850. expires 30d;
  851. access_log off;
  852. }
  853. location ~ .*\.(js|css)?$ {
  854. expires 7d;
  855. access_log off;
  856. }
  857. location ~ /\.ht {
  858. deny all;
  859. }
  860. }
  861. EOF
  862. [ "${https_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  863. echo
  864. ${web_install_dir}/sbin/nginx -t
  865. if [ $? == 0 ]; then
  866. echo "Reload Nginx......"
  867. ${web_install_dir}/sbin/nginx -s reload
  868. else
  869. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  870. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  871. fi
  872. # Apache
  873. if [ "${Apache_main_ver}" == '24' ]; then
  874. if [ -e "${php_install_dir}/sbin/php-fpm" ] && [ -n "`grep -E ^LoadModule.*mod_proxy_fcgi.so ${apache_install_dir}/conf/httpd.conf`" ]; then
  875. Apache_fcgi=$(echo -e "<Files ~ (\\.user.ini|\\.htaccess|\\.git|\\.svn|\\.project|LICENSE|README.md)\$>\n Order allow,deny\n Deny from all\n </Files>\n <FilesMatch \\.php\$>\n SetHandler \"proxy:unix:/dev/shm/php${mphp_ver}-cgi.sock|fcgi://localhost\"\n </FilesMatch>")
  876. fi
  877. fi
  878. [ ! -d ${apache_install_dir}/conf/vhost ] && mkdir ${apache_install_dir}/conf/vhost
  879. cat > ${apache_install_dir}/conf/vhost/${domain}.conf << EOF
  880. <VirtualHost *:88>
  881. ServerAdmin admin@example.com
  882. DocumentRoot "${vhostdir}"
  883. ServerName ${domain}
  884. ${Apache_Domain_alias}
  885. ${Apache_SSL}
  886. ErrorLog "${wwwlogs_dir}/${domain}_error_apache.log"
  887. ${Apache_log}
  888. ${Apache_fcgi}
  889. <Directory "${vhostdir}">
  890. SetOutputFilter DEFLATE
  891. Options FollowSymLinks ExecCGI
  892. ${Apache_grant}
  893. AllowOverride All
  894. Order allow,deny
  895. Allow from all
  896. DirectoryIndex index.html index.php
  897. </Directory>
  898. </VirtualHost>
  899. EOF
  900. echo
  901. ${apache_install_dir}/bin/apachectl -t
  902. if [ $? == 0 ]; then
  903. echo "Restart Apache......"
  904. ${apache_install_dir}/bin/apachectl -k graceful
  905. else
  906. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  907. exit 1
  908. fi
  909. printf "
  910. #######################################################################
  911. # OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+ #
  912. # For more information please visit https://oneinstack.com #
  913. #######################################################################
  914. "
  915. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  916. echo "$(printf "%-30s" "Nginx Virtualhost conf:")${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND}"
  917. echo "$(printf "%-30s" "Apache Virtualhost conf:")${CMSG}${apache_install_dir}/conf/vhost/${domain}.conf${CEND}"
  918. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  919. Print_SSL
  920. }
  921. Add_Vhost() {
  922. if [ -e "${web_install_dir}/sbin/nginx" -a ! -e "${apache_install_dir}/bin/httpd" ]; then
  923. Choose_ENV
  924. Input_Add_domain
  925. Nginx_anti_hotlinking
  926. if [ "${NGX_FLAG}" == "java" ]; then
  927. Nginx_log
  928. Create_nginx_tomcat_conf
  929. else
  930. Nginx_rewrite
  931. Nginx_log
  932. Create_nginx_phpfpm_hhvm_conf
  933. fi
  934. elif [ ! -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  935. Choose_ENV
  936. Input_Add_domain
  937. Apache_log
  938. Create_apache_conf
  939. elif [ ! -e "${web_install_dir}/sbin/nginx" -a ! -e "${apache_install_dir}/bin/httpd" -a -e "${tomcat_install_dir}/conf/server.xml" ]; then
  940. Choose_ENV
  941. Input_Add_domain
  942. Create_tomcat_conf
  943. elif [ -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  944. Choose_ENV
  945. Input_Add_domain
  946. Nginx_anti_hotlinking
  947. if [ "${NGX_FLAG}" == "java" ]; then
  948. Nginx_log
  949. Create_nginx_tomcat_conf
  950. elif [ "${NGX_FLAG}" == "hhvm" ]; then
  951. Nginx_rewrite
  952. Nginx_log
  953. Create_nginx_phpfpm_hhvm_conf
  954. elif [ "${NGX_FLAG}" == "php" ]; then
  955. Nginx_log
  956. Apache_log
  957. Create_nginx_apache_modphp_conf
  958. fi
  959. else
  960. echo "Error! ${CFAILURE}Web server${CEND} not found!"
  961. fi
  962. }
  963. Del_NGX_Vhost() {
  964. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  965. [ -d "${web_install_dir}/conf/vhost" ] && Domain_List=$(ls ${web_install_dir}/conf/vhost | sed "s@.conf@@g")
  966. if [ -n "${Domain_List}" ]; then
  967. echo
  968. echo "Virtualhost list:"
  969. echo ${CMSG}${Domain_List}${CEND}
  970. while :; do echo
  971. read -e -p "Please input a domain you want to delete: " domain
  972. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  973. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  974. else
  975. if [ -e "${web_install_dir}/conf/vhost/${domain}.conf" ]; then
  976. Directory=$(grep '^ root' ${web_install_dir}/conf/vhost/${domain}.conf | head -1 | awk -F'[ ;]' '{print $(NF-1)}')
  977. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  978. [ -e "${web_install_dir}/conf/ssl/${domain}.crt" ] && rm -f ${web_install_dir}/conf/ssl/${domain}.{crt,key}
  979. ${web_install_dir}/sbin/nginx -s reload
  980. while :; do echo
  981. read -e -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_flag
  982. if [[ ! ${Del_Vhost_wwwroot_flag} =~ ^[y,n]$ ]]; then
  983. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  984. else
  985. break
  986. fi
  987. done
  988. if [ "${Del_Vhost_wwwroot_flag}" == 'y' ]; then
  989. if [ "${quiet_flag}" != 'y' ]; then
  990. echo "Press Ctrl+c to cancel or Press any key to continue..."
  991. char=$(get_char)
  992. fi
  993. rm -rf ${Directory}
  994. fi
  995. echo
  996. echo "${CMSG}Domain: ${domain} has been deleted.${CEND}"
  997. echo
  998. else
  999. echo "${CWARNING}Virtualhost: ${domain} was not exist! ${CEND}"
  1000. fi
  1001. break
  1002. fi
  1003. done
  1004. else
  1005. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1006. fi
  1007. fi
  1008. }
  1009. Del_Apache_Vhost() {
  1010. if [ -e "${apache_install_dir}/bin/httpd" ]; then
  1011. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  1012. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  1013. ${apache_install_dir}/bin/apachectl -k graceful
  1014. else
  1015. Domain_List=$(ls ${apache_install_dir}/conf/vhost | grep -v '0.conf' | sed "s@.conf@@g")
  1016. if [ -n "${Domain_List}" ]; then
  1017. echo
  1018. echo "Virtualhost list:"
  1019. echo ${CMSG}${Domain_List}${CEND}
  1020. while :; do echo
  1021. read -e -p "Please input a domain you want to delete: " domain
  1022. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  1023. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  1024. else
  1025. if [ -e "${apache_install_dir}/conf/vhost/${domain}.conf" ]; then
  1026. Directory=$(grep '^<Directory ' ${apache_install_dir}/conf/vhost/${domain}.conf | head -1 | awk -F'"' '{print $2}')
  1027. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  1028. [ -e "${apache_install_dir}/conf/ssl/${domain}.crt" ] && rm -f ${apache_install_dir}/conf/ssl/${domain}.{crt,key}
  1029. ${apache_install_dir}/bin/apachectl -k graceful
  1030. while :; do echo
  1031. read -e -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_flag
  1032. if [[ ! ${Del_Vhost_wwwroot_flag} =~ ^[y,n]$ ]]; then
  1033. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  1034. else
  1035. break
  1036. fi
  1037. done
  1038. if [ "${Del_Vhost_wwwroot_flag}" == 'y' ]; then
  1039. if [ "${quiet_flag}" != 'y' ]; then
  1040. echo "Press Ctrl+c to cancel or Press any key to continue..."
  1041. char=$(get_char)
  1042. fi
  1043. rm -rf ${Directory}
  1044. fi
  1045. echo "${CSUCCESS}Domain: ${domain} has been deleted.${CEND}"
  1046. else
  1047. echo "${CWARNING}Virtualhost: ${domain} was not exist! ${CEND}"
  1048. fi
  1049. break
  1050. fi
  1051. done
  1052. else
  1053. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1054. fi
  1055. fi
  1056. fi
  1057. }
  1058. Del_Tomcat_Vhost() {
  1059. if [ -e "${tomcat_install_dir}/conf/server.xml" ]; then
  1060. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  1061. if [ -n "$(echo ${domain} | grep '.*\..*')" ] && [ -n "$(grep vhost-${domain} ${tomcat_install_dir}/conf/server.xml)" ]; then
  1062. sed -i /vhost-${domain}/d ${tomcat_install_dir}/conf/server.xml
  1063. rm -f ${tomcat_install_dir}/conf/vhost/${domain}.xml
  1064. service tomcat restart
  1065. fi
  1066. else
  1067. Domain_List=$(ls ${tomcat_install_dir}/conf/vhost | grep -v 'localhost.xml' | sed "s@.xml@@g")
  1068. if [ -n "${Domain_List}" ]; then
  1069. echo
  1070. echo "Virtualhost list:"
  1071. echo ${CMSG}${Domain_List}${CEND}
  1072. while :; do echo
  1073. read -e -p "Please input a domain you want to delete: " domain
  1074. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  1075. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  1076. else
  1077. if [ -n "$(grep vhost-${domain} ${tomcat_install_dir}/conf/server.xml)" ]; then
  1078. sed -i /vhost-${domain}/d ${tomcat_install_dir}/conf/server.xml
  1079. rm -f ${tomcat_install_dir}/conf/vhost/${domain}.xml
  1080. service tomcat restart
  1081. while :; do echo
  1082. read -e -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_flag
  1083. if [[ ! ${Del_Vhost_wwwroot_flag} =~ ^[y,n]$ ]]; then
  1084. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  1085. else
  1086. break
  1087. fi
  1088. done
  1089. if [ "${Del_Vhost_wwwroot_flag}" == 'y' ]; then
  1090. if [ "${quiet_flag}" != 'y' ]; then
  1091. echo "Press Ctrl+c to cancel or Press any key to continue..."
  1092. char=$(get_char)
  1093. fi
  1094. rm -rf ${Directory}
  1095. fi
  1096. echo "${CSUCCESS}Domain: ${domain} has been deleted.${CEND}"
  1097. else
  1098. echo "${CWARNING}Virtualhost: ${domain} was not exist! ${CEND}"
  1099. fi
  1100. break
  1101. fi
  1102. done
  1103. else
  1104. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1105. fi
  1106. fi
  1107. fi
  1108. }
  1109. List_Vhost() {
  1110. [ -e "${tomcat_install_dir}/conf/server.xml" -a ! -d "${web_install_dir}/sbin/nginx" ] && Domain_List=$(ls ${tomcat_install_dir}/conf/vhost | grep -v 'localhost.xml' | sed "s@.xml@@g")
  1111. [ -d "${web_install_dir}/conf/vhost" ] && Domain_List=$(ls ${web_install_dir}/conf/vhost | sed "s@.conf@@g")
  1112. [ -e "${apache_install_dir}/bin/httpd" -a ! -d "${web_install_dir}/conf/vhost" ] && Domain_List=$(ls ${apache_install_dir}/conf/vhost | grep -v '0.conf' | sed "s@.conf@@g")
  1113. if [ -n "${Domain_List}" ]; then
  1114. echo
  1115. echo "Virtualhost list:"
  1116. for D in ${Domain_List}; do echo ${CMSG}${D}${CEND}; done
  1117. else
  1118. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1119. fi
  1120. }
  1121. if [ ${ARG_NUM} == 0 ]; then
  1122. Add_Vhost
  1123. else
  1124. [ "${add_flag}" == 'y' -o "${sslquiet_flag}" == 'y' ] && Add_Vhost
  1125. [ "${list_flag}" == 'y' ] && List_Vhost
  1126. [ "${delete_flag}" == 'y' ] && { Del_NGX_Vhost; Del_Apache_Vhost; Del_Tomcat_Vhost; }
  1127. fi