LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Embedding script in apache2.conf (https://www.linuxquestions.org/questions/linux-general-1/embedding-script-in-apache2-conf-4175735725/)

BluePukeko 04-06-2024 12:15 AM

Embedding script in apache2.conf
 
I have an "interesting" problem, mostly caused by my curiosity, that I hope somebody can shine a light on for me.
I have a number of VM's running under ProxMox with one being a NFS server to share the majority of the disk space over all the VM's rather than guessing the amount of disk that each VM will require for data storage.
While I've only got two VM's running apache so far, I will probably have most of them doing so.
The set up so far has the two VM's sharing the /etc/apache directory and therefore sharing the apache.conf file.
Obviously each of the VM's will need to, at a minimum, access different website conf files, which is where my problem comes in.
I've written a small bash script that displays the hostname of the machine and using RewriteMap to capture the output of the script and store that in an environment variable which I then use to a) set the servername and b) include the required website conf files.

The script when ran outside of apache, as root, runs and displays the machine hostname. I changed the owner group to www-data:www-data and still no joy within Apache load or restart.
Script permissions are: xrwxr-xr- so should run happily when called from apache.

The coding within apache2.conf is:

RewriteEngine on
RewriteMap hostname prg:/etc/apache2/hostname.sh

# Use IfDefine to include configuration based on the value of HOSTNAME
<IfDefine HOSTNAME>
# Include configuration file based on hostname
IncludeOptional hosts-available/%{ENV:HOSTNAME}.conf
</IfDefine>


**** AND

<IfDefine HOSTNAME>
# Include virtual machine sites-enabled file(s) based on hostname
<If "%{ENV:HOSTNAME} == 'bpg169.HOST'">
# Directives specific to 120.138.17.169
IncludeOptional sites-enabled/bluehost/*.conf
IncludeOptional sites-enabled/bluepress/*.conf
IncludeOptional sites-enabled/bluewiki/*.conf
</If>
<ElseIf "%{ENV:HOSTNAME} == 'bpg-170-DATA'">
# Directives specific to 120.138.17.170
IncludeOptional sites-enabled/bluedata/*.conf
</ElseIf>
</IfDefine>



Appreciate help in spotting the problem

Turbocapitalist 04-06-2024 01:10 AM

Quote:

Originally Posted by BluePukeko (Post 6494380)
The script when ran outside of apache, as root, runs and displays the machine hostname. I changed the owner group to www-data:www-data and still no joy within Apache load or restart.

It is not a sound idea for Apache to have write access to scripts which it can run. So might be advisable to change the permissions back.

Quote:

Originally Posted by BluePukeko (Post 6494380)
RewriteMap hostname prg:/etc/apache2/hostname.sh

I'm not sure is an efficient way since the prg: method creates a bottleneck which pinches on each and every request to the server:

https://httpd.apache.org/docs/2.4/re...temap.html#prg

What you might do instead could be to use a separate, custom *.conf file, fetched via Include, which has contents which vary per server. There are several ways to do that.

BluePukeko 04-06-2024 06:33 PM

From what I can deduce from further testing, the script is not being run.
My assumption has to be that permissions somewhere are preventing this from happening.
The script is located in /etc/apache2 directory:
drwxr-xr-x 116 root root 4.0K Apr 6 19:33 etc
drwxr-xr-x 11 www-data www-data 4.0K Apr 7 11:26 apache2
-rwxr-xr-x 1 www-data www-data 54 Apr 7 11:23 hostname.sh

the apache2 directory a mount point from the shared drive.

An obvious quick and dirty option to, at least temporarily, get around this would be to to have a hostname.conf file in the local file system that contains the required hostname


All times are GMT -5. The time now is 04:00 PM.