text apache ssl vhost

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text apache ssl vhost相关的知识,希望对你有一定的参考价值。

for ARGUMENT in "$@"; do
    KEY=$(echo $ARGUMENT | cut -f1 -d=)
    VALUE=$(echo $ARGUMENT | cut -f2 -d=)
    case "$KEY" in
    add_node) add_node=${VALUE} ;;
    url) url=${VALUE} ;;
    *) ;;
    esac
done

if [ "$(whoami)" != 'root' ]; then
    echo $"You have no permission to run $0 as non-root user. Use sudo"
    exit 1
fi

if [ "$1" = 'install' ]; then
    apt-get update
    apt-get install -y apt-transport-https lsb-release ca-certificates curl gnupg
    curl https://packages.sury.org/php/apt.gpg | apt-key add -
    echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" >/etc/apt/sources.list.d/php.list
    apt-get update
    apt-get install -y php5.6 sqlite apache2
    curl -O https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
    tar -xvzf ioncube_loaders_lin_x86-64.tar.gz
    EXT_DIR=$(php -i | grep extension_dir | cut -d '=' -f3 | cut -c 3-)
    cp ioncube/ioncube_loader_lin_5.6.so ${EXT_DIR}
    rm -rf ioncube_loaders_lin_x86-64.tar.gz ioncube
    echo "zend_extension=${EXT_DIR}/ioncube_loader_lin_5.6.so" >>/etc/php/5.6/apache2/php.ini
    echo "zend_extension=${EXT_DIR}/ioncube_loader_lin_5.6.so" >>/etc/php/5.6/cli/php.ini

    curl -O https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh
    chmod +x ./acme.sh
    ./acme.sh --install

    ### enable required modules for apache2 with https
    a2enmod headers
    a2enmod rewrite
    a2enmod ssl
    service apache2 restart

fi

email='webmaster@localhost'
sitesEnabled='/etc/apache2/sites-enabled/'
sitesAvailable='/etc/apache2/sites-available/'
userDir='/var/www/'
sitesAvailabledomain=$sitesAvailable${add_node}.conf

if [ "$rootDir" == "" ]; then
    rootDir=${add_node//./}
fi

### if root dir starts with '/', don't use /var/www as default starting point
if [[ "$rootDir" =~ ^/ ]]; then
    userDir=''
fi

rootDir=${userDir}${rootDir}

if [ "$add_node" != '' ]; then
    ### check if directory exists or not
    if ! [ -d $rootDir ]; then
        ### create the directory
        mkdir $rootDir
        ### give permission to root dir
        chmod 777 $rootDir
    fi

    if ! echo "
<VirtualHost *:80>
    DocumentRoot $rootDir
</VirtualHost>
" >$sitesAvailabledomain; then
        echo -e $"There is an ERROR creating ${add_node} file"
        exit
    else
        echo -e $"\nNew vhost created\n"
    fi
    ### enable website
    a2ensite ${add_node}
    ### restart Apache
    service apache2 restart

    ## issue cert
    mkdir -p /etc/apache2/ssl
    ./acme.sh --issue --apache -d ${add_node} &&
        if ! echo "
		<IfModule mod_ssl.c>
            <VirtualHost *:443>
                DocumentRoot $rootDir
                SSLEngine on
                SSLCertificateFile    /etc/apache2/ssl/${add_node}.crt
                SSLCertificateKeyFile /etc/apache2/ssl/${add_node}.key
            </VirtualHost>
        </IfModule>" >>$sitesAvailabledomain; then
            echo -e $"There is an ERROR adding HTTPS vhost ${add_node}"
            exit
        else
            echo -e $"\nHTTPS vhost Added\n"
        fi
    ./acme.sh --install-cert -d ${add_node} \
        --cert-file /etc/apache2/ssl/${add_node}.crt \
        --key-file /etc/apache2/ssl/${add_node}.key \
        --fullchain-file /etc/apache2/ssl/letsencrypt.pem \
        --reloadcmd "service apache2 reload"
fi

if [ "$url" != '' ]; then
    curl ${url} -o ${rootDir}/index.php &&
        chmod 777 ${rootDir}/index.php
fi

以上是关于text apache ssl vhost的主要内容,如果未能解决你的问题,请参考以下文章

apache vhosts https/ssl 子域始终重定向到非 https 主页面

怎样配置apache的vhosts文件

text 创建apache2虚拟主机的脚本#bash #linux #apache #wsl #host #vhost

https----------如何在phpstudy环境下配置apache的https访问以及访问http自动跳转成https

怎样在windows下配置apache vhost

为 XAMPP 启用 SSL 后 Apache 无法启动