Does vcl.load include related files? - varnish

In Varnish, we can load a particular configuration file and tell Varnish to use it.
For example, a bash script:
#!/bin/bash
# Generate a unique timestamp ID for this version of the VCL
TIME=$(date +%s)
# Load the file into memory
varnishadm vcl.load varnish_$TIME /etc/varnish/default.vcl
# Active this Varnish config
varnishadm vcl.use varnish_$TIME
Run with:
$ ./varnishconf
VCL compiled.
VCL 'varnish_1604136350' now active
However, if default.vcl includes other vcl files, it's not clear if vcl.use will also use that version of those included files?
For example, in default.vcl:
include "includes/backend.vcl";
is backends.vcl state included in that vcl.use version?
Does varnish include the dependent included files from vcl.load in vcl.use ?

Yes, Varnish processes the full VCL file when vcl.load is executed.
varnishadm vcl.load triggers the VCC, which is the compiler. The same VCC is triggered when varnishd is started, so there's not really a difference here.
In regards to include files: when the VCC thread is started, every include statement is parsed and the content it refers to is pasted inline. Once all includes have been parsed, Varnish can start tokenizing, and compiling the full VCL.

Related

Can't get varnish to see backend

I installed Varnish locally on OSX to test it out. I have a working backend running on localhost:8085 that returns a 200. I installed varnish with Brew but don't have the Brew service running, I instead run Varnish with
varnishd -n /usr/local/var/varnish -f /usr/local/etc/varnish/default.vcl -T 127.0.0.1:8085 -a 127.0.0.1:8090 -F
which prints
Debug: Platform: Darwin,17.5.0,x86_64,-jnone,-sdefault,-sdefault,-hcritbit
Debug: Child (57659) Started
Info: Child (57659) said Child starts
and creates a vcl_boot.* folder in /usr/local/var/varnish
When i go to 127.0.0.1:8090 I see varnish is running but just get
Error 503 Backend fetch failed
Backend fetch failed
My /usr/local/etc/varnish/default.vcl is pretty much the default:
#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples.
# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8085";
}
sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.
}
sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
}
sub vcl_deliver {
# Happens when we have all the pieces we need, and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}
Does anyone know what I could be missing?
Thanks!
In your command to run Varnish, I think you mistakenly use -T 127.0.0.1:8085. The -T switch is for:
Offer a management interface on the specified address and port.
So you're binding the Varnish management interface to the same port as your backend. Wonder why that doesn't fail anyway.

Recovering loaded Varnish config

I've accidentally copied over my default.vcl and erased my fairly complex configuration. So long as I don't try to reload the configuration or restart Varnish everything is running fine - I'm hoping there's a way to view or "extract" my loaded configuration from Varnish so I don't have to rewrite it from scratch. Thanks for any ideas.
You may as well login in the admin console ( varnishadm) and run vcl.list to list all the vcl that are loaded. And then vcl.show to display the most recent one.
Vcl list is cleared when varnish service is restarted or stopped.
Solved my issue by recovering my loaded config file using -
grep -i -a -B100 -A100 'text' /dev/vda
Replaced 'text' with a line of code I remembered from the config.

How to enable php in NixOs

I'm trying to setup an LAMP environment with NixOs.
I managed to have mysql and apache running, but I can't find a way
to enable php.
At the moment, apache is serving php file as text instead of executing it.
I've seen there is a enablePHP option in the appache-httpd/default.nix file but it doesn't seem visible (it doesn't appear when I do man configuration.nix and I get an error message if I try to set it to true).
Most likely the version of nixpkgs used to build your system (and the configuration.nix man page) is older than the version of nixpkgs you are looking at. After an update of your system the option should be documented in the configuration.nix man page and work as expected.
I successfully use enablePHP and enableUserDir to render php files in my user's public_html. An .htaccess file with DirectoryIndex index.php further enables php index files.
I'm also in the process of setting up a php stack (using nginx / php-fpm) and I found the following, which might answer your question.
Use the extraModules parameter of the httpd config to enable the php module, like so:
extraModules = [
{ name = "php5"; path = "${pkgs.php}/modules/libphp5.so"; }
];
I found this example here: https://github.com/svanderburg/disnix-stafftracker-php-example/blob/master/deployment/configurations/test-vm1-httpd.nix

Apache httpd cant write to /etc/sysconfig/network-scripts/

Im trying to use a script ,thats started by apache through the server, to change the ifcfg-eth0 file in network-scripts.
I have SELinux disabled so thats not the issue. Also I changed the whole /etc/ group and user to apache, yet it still did not work.
The script does work if I put the file in /var/www/cgi-bin.
I also get a permission denied error in the apache log file.
I can't bring myself to help you make Apache write to files in /etc/sysconfig/network-scripts/. But there is another option: create a symlink from /etc/sysconfig/network-scripts/ifcfg-eth0 to a file that Apache can write to, for example:
mv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak
ln -s /var/www/cgi-bin/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0
This way, your (ahem, dangerous) CGI script can rewrite the file in /var/www/cgi-bin, and the system can get the network settings from it.

Apache ScriptAlias unable to set Script parameter

I'm porting over a Windows httpd.conf file to a linux apache server. I'm pretty much done, but the only error i get is:
* Starting web server apache2 [Tue Feb 07 14:24:34 2012] [warn] The Alias directive in /etc/apache2/httpd.conf at line 449 will probably never match because it overlaps an earlier Alias.
Syntax error on line 461 of /etc/apache2/httpd.conf:
Invalid command 'Script', perhaps misspelled or defined by a module not included in the server configuration
Action 'start' failed.
The Apache error log may have more information.
My httpd.conf file at line 461 is as follows:
ScriptAlias /cgi-bin "/var/www/cgi-bin"
Script PUT /cgi-bin/put.py
Looks like the mod_actions module isn't loaded. This module enables the use of Scripts.
If you activate this module, the error message should disappear.
You can typically activate mod_actions by creating a symlink from the respective mods_available directory like this:
ln -s /etc/apache2/mods-available/actions.load /etc/apache2/mods-enabled/actions.load
The directory structure can be different on your machine, but the principle remains the same: There are available modules and these can be activated by symlinking into the mods_enabled dir.

Resources