1
0

vhost.sh 58 KB

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