-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-apache-proxy.sh
More file actions
executable file
Β·164 lines (133 loc) Β· 4.93 KB
/
setup-apache-proxy.sh
File metadata and controls
executable file
Β·164 lines (133 loc) Β· 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# Setup Apache as Reverse Proxy for Irrigation Controller
# Run this script to configure Apache on the Asustor NAS
set -e
NAS_HOST="nas"
APACHE_CONF_DIR="/volume1/.@plugins/AppCentral/httpd-2.4.43/data/conf"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'
echo "============================================"
echo " Apache Reverse Proxy Setup"
echo " Irrigation Controller"
echo "============================================"
echo ""
# Check connectivity
echo -e "${GREEN}π${NC} Testing connection to NAS..."
if ! ssh -o ConnectTimeout=5 "$NAS_HOST" 'echo "Connected"' >/dev/null 2>&1; then
echo -e "${RED}β${NC} Cannot connect to NAS"
exit 1
fi
echo -e "${GREEN}β${NC} Connected"
echo ""
# Deploy configuration
echo -e "${BLUE}π${NC} Deploying Apache configuration..."
echo ""
ssh -t "$NAS_HOST" sh << 'ENDSSH'
set -e
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
APACHE_CONF="/volume1/.@plugins/AppCentral/httpd-2.4.43/data/conf"
# Enable required modules
echo -e "${GREEN}π¦${NC} Enabling required Apache modules..."
cd "$APACHE_CONF/mods-enabled"
# Enable proxy_http if not already enabled
if [ ! -L proxy_http.conf ]; then
ln -s ../mods-available/proxy_http.conf proxy_http.conf
echo " β Enabled mod_proxy_http"
else
echo " β mod_proxy_http already enabled"
fi
# Enable rewrite if not already enabled
if [ ! -L rewrite.conf ]; then
ln -s ../mods-available/rewrite.conf rewrite.conf 2>/dev/null || echo " β mod_rewrite may not be available"
fi
# Enable headers if not already enabled
if [ ! -L headers.conf ]; then
ln -s ../mods-available/headers.conf headers.conf 2>/dev/null || echo " β mod_headers may not be available"
fi
echo ""
# Create irrigation site configuration
echo -e "${GREEN}π${NC} Creating irrigation site configuration..."
cat > "$APACHE_CONF/sites-available/irrigation" << 'EOF'
# Irrigation Controller - Apache Reverse Proxy Configuration
# Listen on port 80
Listen 80
<VirtualHost *:80>
ServerName 192.168.20.92
ServerAdmin jonclow@redmercury.co.nz
# Reverse proxy to Docker container
ProxyPreserveHost On
ProxyPass /socket.io/ http://localhost:3000/socket.io/
ProxyPassReverse /socket.io/ http://localhost:3000/socket.io/
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
# Proxy settings for WebSocket/Socket.IO
<Location /socket.io/>
ProxyPass http://localhost:3000/socket.io/
ProxyPassReverse http://localhost:3000/socket.io/
# Enable WebSocket proxying
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://localhost:3000/socket.io/$1 [P,L]
</Location>
# Security headers
<IfModule mod_headers.c>
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-Content-Type-Options "nosniff"
Header always set X-XSS-Protection "1; mode=block"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>
# Logging
ErrorLog /volume1/.@plugins/AppCentral/httpd-2.4.43/data/logs/irrigation-error.log
CustomLog /volume1/.@plugins/AppCentral/httpd-2.4.43/data/logs/irrigation-access.log combined
# Timeout settings
ProxyTimeout 300
Timeout 300
</VirtualHost>
EOF
echo " β Created irrigation site config"
echo ""
# Disable default site
echo -e "${YELLOW}π§${NC} Disabling default site..."
rm -f "$APACHE_CONF/sites-enabled/@default" 2>/dev/null || true
echo " β Default site disabled"
echo ""
# Enable irrigation site
echo -e "${GREEN}π${NC} Enabling irrigation site..."
cd "$APACHE_CONF/sites-enabled"
ln -sf ../sites-available/irrigation irrigation
echo " β Irrigation site enabled"
echo ""
# Create logs directory if it doesn't exist
mkdir -p /volume1/.@plugins/AppCentral/httpd-2.4.43/data/logs
echo -e "${GREEN}β${NC} Apache configuration complete!"
echo ""
echo "Next steps:"
echo " 1. Deploy Docker container: ./docker-deploy-nas.sh"
echo " 2. Start Apache (see instructions below)"
ENDSSH
echo ""
echo "============================================"
echo -e "${GREEN}β Apache configured successfully${NC}"
echo "============================================"
echo ""
echo "To start Apache on the NAS:"
echo ""
echo "Option 1: Via Asustor ADM (Recommended)"
echo " 1. Log into ADM at https://192.168.20.92:8014"
echo " 2. Go to App Central"
echo " 3. Find 'Apache Http Server'"
echo " 4. Click 'Start' or 'Enable'"
echo ""
echo "Option 2: Via Command Line (if available)"
echo " ssh nas '/volume1/.@plugins/AppCentral/httpd-2.4.43/CONTROL/start-stop.sh start'"
echo ""
echo "After starting Apache:"
echo " - Deploy Docker: ./docker-deploy-nas.sh"
echo " - Access at: http://192.168.20.92/"
echo ""