I'm configuring Verniz to use woocommerce and I made some changes to the "default.vcl" file to separate the cache for mobile and desktop because my site appears different on mobile, this is the code:
vcl 4.0;
backend default { .host = "144.126.137.13"; .port = "8181";}
include "/etc/varnish/conf.d/vhosts.conf";
## ## Not complete default.vcl code
# Routine to try and identify device
sub identify_device {
# Default to thinking it's desktop
set req.http.X-UA-Device = "desktop";
if (req.http.User-Agent ~ "iPad" ) {
# It says its a iPad - so let's give them the tablet-site
set req.http.X-UA-Device = "tablet";
}
else if (req.http.User-Agent ~ "iP(hone|od)" || req.http.User-Agent ~ "Android" || req.http.User-Agent ~ "Windows Phone" || req.http.User-Agent ~ "[ (]BlackBerry;") {
# It says its a iPhone, iPod, Android or BlackBerry - so let's give them the touch-site..
set req.http.X-UA-Device = "smartphone";
}
else if (req.http.User-Agent ~ "Kindle" || req.http.User-Agent ~ "^nook browser") {
set req.http.X-UA-Device = "ereader";
}
else if (req.http.User-Agent ~ "SymbianOS" || req.http.User-Agent ~ "^BlackBerry" || req.http.User-Agent ~ "^SonyEricsson" || req.http.User-Agent ~ "^Nokia" || req.http.User-Agent ~ "^SAMSUNG" || req.http.User-Agent ~ "^LG" || req.http.User-Agent ~ "IEMobile" || req.http.User-Agent ~ "Windows CE") {
# Some other sort of mobile
set req.http.X-UA-Device = "mobile-other";
}
}
sub vcl_recv {
call identify_device;
}
sub vcl_hash {
hash_data(req.url);
if (req.http.X-UA-Device){
# Add device info with uniqueID cache
hash_data(req.http.X-UA-Device);
}
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
return (lookup);
}
# Unset Cookies except for WordPress admin and WooCommerce pages
if (!(req.url ~ "(wp-login|wp-admin|carrinho|cart|add-to-cart|minha-conta/*|wc-api*|checkout|escritorio-virtual|addons|logout|lost-password|produto/*)")) {
unset req.http.cookie;
}
# Pass through the WooCommerce dynamic pages
if (req.url ~ "^/(carrinho|cart|add-to-cart|minha-conta/*|escritorio-virtual/*|checkout|wc-api/*|addons|logout|lost-password|product/*)") {
return (pass);
}
# Pass through the WooCommerce add to cart
if (req.url ~ "\?add-to-cart=" ) {
return (pass);
}
# Pass through the WooCommerce API
if (req.url ~ "\?wc-api=" ) {
return (pass);
}
# Block access to php admin pages via website
if (req.url ~ "^/phpmyadmin/.*$" || req.url ~ "^/phppgadmin/.*$" || req.url ~ "^/server-status.*$") {
error 403 "For security reasons, this URL is only accesible using localhost (127.0.0.1) as the hostname";
}
But now the server is not booting and I can't solve it, can someone help me? I am posting the error log below:
● varnish.service - Varnish Cache, a high-performance HTTP accelerator
Loaded: loaded (/usr/lib/systemd/system/varnish.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2023-03-01 07:55:27 CST; 5min ago
Process: 4116 ExecStart=/usr/sbin/varnishd -P /var/run/varnish.pid -f $VARNISH_VCL_CONF -a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} -S $VARNISH_SECRET_FILE -s $VARNISH_STORAGE $DAEMON_OPTS (code=exited, status=255)
Main PID: 30643 (code=exited, status=0/SUCCESS)
Mar 01 07:55:27 server.ayanlife.com varnishd[4116]: Found: 'if' at
Mar 01 07:55:27 server.ayanlife.com varnishd[4116]: ('/etc/varnish/default.vcl' Line 50 Pos 1)
Mar 01 07:55:27 server.ayanlife.com varnishd[4116]: if (!(req.url ~ "(wp-login|wp-admin|carrinho|cart|add-to-cart|minha-conta/*|wc-api*|checkout|escritorio-virtual|addons|logout|lost-password|produto/*)")) {
Mar 01 07:55:27 server.ayanlife.com varnishd[4116]: ##----------------------------------------------------------------------------------------------------------------------------------------------------------
Mar 01 07:55:27 server.ayanlife.com varnishd[4116]: Running VCC-compiler failed, exited with 2
Mar 01 07:55:27 server.ayanlife.com varnishd[4116]: VCL compilation failed
Mar 01 07:55:27 server.ayanlife.com systemd[1]: varnish.service: control process exited, code=exited status=255
Mar 01 07:55:27 server.ayanlife.com systemd[1]: Failed to start Varnish Cache, a high-performance HTTP accelerator.
Mar 01 07:55:27 server.ayanlife.com systemd[1]: Unit varnish.service entered failed state.
Mar 01 07:55:27 server.ayanlife.com systemd[1]: varnish.service failed.
I really need this help