5

I have multiple django applications on my server that run each within their own virtualhosts, bound to different ports. (I do this so as to isolate each WSGIProcessGroup).

Now I would like to proxy each application to the port 80 for a simplicity matter.

For one application, I do something like this:

Listen 8101
<VirtualHost 127.0.0.1:8101>
    WSGIProcessGroup app1
    WSGIDaemonProcess app1 display-name=%{GROUP}
    WSGIScriptAlias /app1 "/var/django_apps/app1/app1.wsgi"
</VirtualHost>

<VirtualHost *:80>
    ProxyPass /app1 http://localhost:8101/app1
    ProxyPassReverse /app1 http://localhost:8101/app1
</VirtualHost>

Now, for simplicity in enabling or disabling some applications, when I have another app running, I have another .conf file containing this:

Listen 8102
<VirtualHost 127.0.0.1:8102>
    WSGIProcessGroup app2
    WSGIDaemonProcess app2 display-name=%{GROUP}
    WSGIScriptAlias /app2 "/var/django_apps/app2/app2.wsgi"
</VirtualHost>

<VirtualHost *:80>
    ProxyPass /app2 http://localhost:8102/app2
    ProxyPassReverse /app2 http://localhost:8102/app2
</VirtualHost>

But this second <VirtualHost *:80> is not used, which seems normal considering the apache configuration syntax.

However, I would like for this bit of config to live just beside the application declaration, so I can have things that belong together in just one file.

Would there be something I could do for that matter? I was thinking about using an include directive somehow, but I have very little knowledge about apache configuration, and i don't think I can find a solution all by myself :)

What do you think?

Cheers

Olivier H
  • 245
  • 1
  • 3
  • 9

1 Answers1

6

The include directive would let you structure your proxy configuration like this:

proxy.conf:

<VirtualHost *:80>
    Include app1_proxy.conf
    Include app2_proxy.conf
</VirtualHost>

app1_proxy.conf:

ProxyPass /app1 http://localhost:8101/app1
ProxyPassReverse /app1 http://localhost:8101/app1

app2_proxy.conf:

ProxyPass /app2 http://localhost:8102/app2
ProxyPassReverse /app2 http://localhost:8102/app2
sciurus
  • 12,678
  • 2
  • 31
  • 49
  • 1
    So i'll have a single VirtualHost *:80 directive, in which I will include every *.proxyconf file. When I want to remove applications, I'll build a script that will move away (in a subdir for example) app1.conf & app1.proxyconf. – Olivier H Jan 03 '14 at 12:16