LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-17-2014, 10:17 AM   #1
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
apache vhost if then else?


Has anyone been able to create a vhost file that has a configuration dependent upon which server the vhost is being run on?

Essentially, i have a vhost whose config is mostly the same across all servers -- except the IP it runs on which makes it impossible for me to throw it in subversion and just keep the config files the same across all servers. Yes, I am able to do this with Chef, Puppet, Scripting and all the rest.

I am just asking if it is possible with apache alone with if..then..else,. or some variables or something?

Last edited by szboardstretcher; 03-17-2014 at 10:35 AM.
 
Old 03-17-2014, 07:23 PM   #2
choronozon
LQ Newbie
 
Registered: Mar 2009
Distribution: Debian lenny & squeeze servers. Mint 13 and 14 desktops
Posts: 16

Rep: Reputation: 2
I haven't found a way, no. In the end I messed around with apache and made it deliver all pages to a single script, and put the 'if this then else' stuff in there.
 
Old 03-18-2014, 02:02 AM   #3
geox
Member
 
Registered: Jan 2012
Posts: 42

Rep: Reputation: 2
I might be able to almost solve your problem
I use one central script as well to allow for minor changes when I actually serve it to a host. The trick is to use the Include directive inside VirtualHost sections.
I use it to customize various parts per website while keeping most of the configuration generic.

Per website (/etc/apache2/sites-available/mysite.com):
Quote:
<VirtualHost *:80>
ServerName mysite.com

Include /etc/apache2/sites-available/generic.com
CustomLog /var/log/apache2/mysite/access.log combined

<IfModule mod_php5.c>
php_value memory_limit 64M
php_value max_execution_time 45s
</IfModule>
</VirtualHost>
Generic (/etc/apache2/sites-available/generic.com):
Quote:
# This file must be included inside a VirtualHost spec
#<VirtualHost *:80>
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
#</VirtualHost>
The same website but now accessible via ssl (/etc/apache2/sites-available/mysite-ssl.com):
Quote:
<VirtualHost *:443>
ServerName mysite.com:443
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem

Include /etc/apache2/sites-available/generic.com

CustomLog /var/log/apache2/mysite/ssl_access.log combined
</VirtualHost>
After than enable both sites via a2ensite mysite.com; a2ensite mysite-ssl.com
Hope this helps.

Last edited by geox; 03-18-2014 at 02:05 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache Internal Server Redirection vhost => vhost not working [Debian & Apache 2] Smokin... Linux - Server 1 05-26-2013 01:06 PM
Apache ssl on only *one* vhost belorion Linux - Networking 1 12-01-2005 04:59 PM
Apache: Alias is working on ssl vhost but not on mass vhost jonavogt Linux - Software 0 06-07-2005 03:05 PM
vhost in apache jelgavchik Linux - Networking 3 02-07-2005 07:41 PM
apache 1.3 vhost z4Rilla Linux - Software 0 08-03-2003 07:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:41 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