Fix Varnish backend to use server IP instead of 127.0.0.1
Apache VirtualHosts listen on the public IP, not localhost. Script now detects primary server IP and configures Varnish backend accordingly.
This commit is contained in:
@@ -477,13 +477,22 @@ install_varnish() {
|
|||||||
configure_varnish_vcl() {
|
configure_varnish_vcl() {
|
||||||
print_banner "Configuring Varnish VCL"
|
print_banner "Configuring Varnish VCL"
|
||||||
|
|
||||||
|
# Get server's primary IP address for Apache backend
|
||||||
|
local server_ip=$(hostname -I | awk '{print $1}')
|
||||||
|
if [ -z "$server_ip" ]; then
|
||||||
|
server_ip="127.0.0.1"
|
||||||
|
print_warning "Could not detect server IP, using 127.0.0.1"
|
||||||
|
else
|
||||||
|
print_info "Detected server IP: $server_ip"
|
||||||
|
fi
|
||||||
|
|
||||||
# Simple VCL with comprehensive admin page bypasses
|
# Simple VCL with comprehensive admin page bypasses
|
||||||
cat > "$VARNISH_VCL" <<'EOFVCL'
|
cat > "$VARNISH_VCL" <<'EOFVCL'
|
||||||
vcl 4.1;
|
vcl 4.1;
|
||||||
|
|
||||||
# Backend definition - Apache on port 81 (ea-nginx stock port)
|
# Backend definition - Apache on port 81 (ea-nginx stock port)
|
||||||
backend default {
|
backend default {
|
||||||
.host = "127.0.0.1";
|
.host = "SERVER_IP_PLACEHOLDER";
|
||||||
.port = "81";
|
.port = "81";
|
||||||
.connect_timeout = 600s;
|
.connect_timeout = 600s;
|
||||||
.first_byte_timeout = 600s;
|
.first_byte_timeout = 600s;
|
||||||
@@ -606,6 +615,9 @@ sub vcl_deliver {
|
|||||||
}
|
}
|
||||||
EOFVCL
|
EOFVCL
|
||||||
|
|
||||||
|
# Replace placeholder with actual server IP
|
||||||
|
sed -i "s/SERVER_IP_PLACEHOLDER/$server_ip/g" "$VARNISH_VCL"
|
||||||
|
|
||||||
# Test VCL configuration
|
# Test VCL configuration
|
||||||
# Note: /tmp is usually mounted with noexec on cPanel servers, so use -n parameter
|
# Note: /tmp is usually mounted with noexec on cPanel servers, so use -n parameter
|
||||||
# to specify a working directory outside /tmp
|
# to specify a working directory outside /tmp
|
||||||
|
|||||||
Reference in New Issue
Block a user