LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-06-2024, 12:15 AM   #1
BluePukeko
LQ Newbie
 
Registered: Mar 2024
Posts: 5

Rep: Reputation: 0
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
 
Old 04-06-2024, 01:10 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Quote:
Originally Posted by BluePukeko View Post
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 View Post
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.
 
Old 04-06-2024, 06:33 PM   #3
BluePukeko
LQ Newbie
 
Registered: Mar 2024
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
  


Reply

Tags
apache, proxmox, ubuntu



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to write the rewrite rule in /etc/apache2/apache2.conf? luofeiyu Linux - Server 1 09-20-2015 08:11 AM
[SOLVED] Default apache2 /sites-available/000-default and apache2.conf nobuntu Linux - Server 3 02-06-2013 11:05 AM
embedding grails-1.2.2 in apache2 tkmsr Linux - Server 2 04-30-2010 07:28 AM
LXer: Embedding Python In Apache2 With mod_python (Debian/Ubuntu, Fedora/CentOS, Mand LXer Syndicated Linux News 0 07-22-2008 07:20 AM
LXer: Embedding Python In Apache2 With mod_python (Debian Etch) LXer Syndicated Linux News 0 06-22-2008 08:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration