# Create a single config for multiple Apache virtual hosts

**URL:** <https://www.ruby-forum.com/t/create-a-single-config-for-multiple-apache-virtual-hosts/243148>\
**Category:** NGINX\
**Created:** [August 26, 2015, 12:49pm UTC](https://www.ruby-forum.com/t/create-a-single-config-for-multiple-apache-virtual-hosts/243148 "2015-08-26T12:49:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [August 26, 2015, 12:49pm UTC](https://www.ruby-forum.com/t/create-a-single-config-for-multiple-apache-virtual-hosts/243148/1 "2015-08-26T12:49:03Z")

</div>

Hi everyone!

First time posting here, I have been searching online but have not found  
any  
good solutions yet.

I am trying to run nginx as reverse proxy for Apache, running multiple  
virtual hosts (domains) on the same ip.

I wanted to know if it is possible to have a single nginx config, that  
would  
pass the correct url/hostname/path to Apache, without having to create a  
separate server block for each domain. For example if all domain  
directories  
are the same as their hostnames:  
/var/www/mydomain.com/  
/var/www/anotherdomain.org/  
…

If it is - are there any potential issues with this setup?

Thanks in advance!

Posted at Nginx Forum:

> **[Create a single config for multiple Apache virtual hosts.](https://forum.nginx.org/read.php?2,261260,261260#msg-261260)**
>
> Hi everyone! First time posting here, I have been searching online but have not found any good solutions yet. I am trying to run nginx as reverse proxy for Apache, running multiple virtual hosts (domains) on the same ip. I wanted to know if it is...

---

<div class="post-metadata">

**Author:** ![YemSalat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8c91f0/32.png) [@YemSalat](https://www.ruby-forum.com/u/YemSalat)\
**Post date:** [September 1, 2015, 8:20pm UTC](https://www.ruby-forum.com/t/create-a-single-config-for-multiple-apache-virtual-hosts/243148/2 "2015-09-01T20:20:07Z")

</div>

On Wed, Aug 26, 2015 at 06:48:18AM -0400, YemSalat wrote:

Hi there,

> I am trying to run nginx as reverse proxy for Apache, running multiple  
> virtual hosts (domains) on the same ip.
> 
> I wanted to know if it is possible to have a single nginx config, that would  
> pass the correct url/hostname/path to Apache, without having to create a  
> separate server block for each domain.

If nginx is just reverse-proxying everything, then you  
probably just want to send “Host:” using proxy\_set\_header  
([Module ngx\_http\_proxy\_module](http://nginx.org/r/proxy_set_header)), but otherwise there is nothing  
special to do.

> For example if all domain directories  
> are the same as their hostnames:  
> /var/www/mydomain.com/  
> /var/www/anotherdomain.org/  
> …

Since nginx isn’t touching the filesystem, it doesn’t matter.

You’ll have to decide what kind of logging you want – possibly just  
adding “$host” to each line in a single access.log will be enough.

> If it is - are there any potential issues with this setup?

For simple things, none spring to mind.

If you care about upstream (apache) knowing the client IP address,  
you’ll have to allow for that.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
