Skip to content

Commit

Permalink
Apache proxy site-type (#1891)
Browse files Browse the repository at this point in the history
* feat: add apache proxy site-type

* remove .gitignore
  • Loading branch information
ALameLlama authored Oct 6, 2023
1 parent 627825e commit cdda217
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
14 changes: 14 additions & 0 deletions resources/aliases
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ function serve-apache() {
fi
}

function serve-apache-proxy() {
if [[ "$1" && "$2" ]]
then
sudo bash /vagrant/scripts/create-certificate.sh "$1"
sudo dos2unix /vagrant/scripts/site-types/apache-proxy.sh
sudo bash /vagrant/scripts/site-types/apache-proxy.sh "$1" "$2" 80 443 "${3:-8.1}"
else
echo "Error: missing required parameters."
echo "Usage: "
echo " serve-apache-proxy domain port"
fi
}

function serve-laravel() {
if [[ "$1" && "$2" ]]
then
Expand All @@ -143,6 +156,7 @@ function serve-laravel() {
function serve-proxy() {
if [[ "$1" && "$2" ]]
then
sudo bash /vagrant/scripts/create-certificate.sh "$1"
sudo dos2unix /vagrant/scripts/site-types/proxy.sh
sudo bash /vagrant/scripts/site-types/proxy.sh "$1" "$2" 80 443 "${3:-8.1}"
else
Expand Down
104 changes: 104 additions & 0 deletions scripts/site-types/apache-proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash

declare -A params=$6 # Create an associative array
declare -A headers=${9} # Create an associative array
paramsTXT=""
if [ -n "$6" ]; then
for element in "${!params[@]}"
do
paramsTXT="${paramsTXT}
SetEnv ${element} \"${params[$element]}\""
done
fi
headersTXT=""
if [ -n "${9}" ]; then
for element in "${!headers[@]}"
do
headersTXT="${headersTXT}
Header always set ${element} \"${headers[$element]}\""
done
fi

if [ -n "$2" ]
then
if ! [[ "$2" =~ ^[0-9]+$ ]]
then
proxyPass="
ProxyPass / ${2}/
ProxyPassReverse / ${2}/
"
else proxyPass="
ProxyPass / http://127.0.0.1:$2/
ProxyPassReverse / http://127.0.0.1:$2/
"
fi
else proxyPass="
ProxyPass / http://127.0.0.1/
ProxyPassReverse / http://127.0.0.1/
"
fi

export DEBIAN_FRONTEND=noninteractive

sudo service nginx stop
sudo systemctl disable nginx
sudo systemctl enable apache2

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_ajp
sudo a2enmod rewrite
sudo a2enmod deflate
sudo a2enmod headers
sudo a2enmod proxy_balancer
sudo a2enmod proxy_connect
sudo a2enmod proxy_html

block="<VirtualHost *:$3>
ServerAdmin webmaster@localhost
ServerName $1
ServerAlias www.$1
$paramsTXT
$headersTXT
$proxyPass
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
"

echo "$block" > "/etc/apache2/sites-available/$1.conf"
ln -fs "/etc/apache2/sites-available/$1.conf" "/etc/apache2/sites-enabled/$1.conf"

blockssl="<IfModule mod_ssl.c>
<VirtualHost *:$4>
ServerAdmin webmaster@localhost
ServerName $1
ServerAlias www.$1
$paramsTXT
SSLEngine on
SSLCertificateFile /etc/ssl/certs/$1.crt
SSLCertificateKeyFile /etc/ssl/certs/$1.key
$proxyPass
</VirtualHost>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
"

echo "$blockssl" > "/etc/apache2/sites-available/$1-ssl.conf"
ln -fs "/etc/apache2/sites-available/$1-ssl.conf" "/etc/apache2/sites-enabled/$1-ssl.conf"

ps auxw | grep apache2 | grep -v grep > /dev/null

service apache2 restart

if [ $? == 0 ]
then
service apache2 reload
fi

0 comments on commit cdda217

Please sign in to comment.