Howto have multiple root apps in same Apache with NamedVirtualHost ?

40 views
Skip to first unread message

ltrillaud

unread,
Jul 27, 2011, 3:05:36 AM7/27/11
to mod...@googlegroups.com
Hi

I would like to share an Apache to host regular and multiple wsgi applications.

Here are my samples :

First Application default.conf -> static files
<VirtualHost _default_:*>
        DocumentRoot /var/www/html
</VirtualHost>

Second Application app1.conf -> python app
<VirtualHost *:80>
    ServerName app1.exemple.com
    WSGIDaemonProcess app1 user=apache group=apache threads=10 processes=3 python-path=/path/to/app1/python/lib/python2.7/site-packages
    WSGIProcessGroup app1
    WSGIScriptAlias / /path/to/app1.wsgi
</VirtualHost>

Second Application app2.conf -> python app
<VirtualHost *:80>
    ServerName app2.exemple.com
    WSGIDaemonProcess app2 user=apache group=apache threads=10 processes=3 python-path=/path/to/app2/python/lib/python2.7/site-packages
    WSGIProcessGroup app2
    WSGIScriptAlias / /path/to/app2.wsgi
</VirtualHost>

The result should be :
http://www.exemple.com give the content of /var/www/html/index.html
http://app1.exemple.com give the content of the python app1
http://app2.exemple.com give the content of the python app2

But it's not the case because WSGIScriptAlias is server wide. Instead of the expected result, I got the content of app1 for the 3 urls because app1.conf is the first conf in alphabetic order and override the "/" match for any virtualhosts.

If I change these lines :
WSGIScriptAlias /app1 /path/to/app1.wsgi in app1.conf
WSGIScriptAlias /app2 /path/to/app2.wsgi in app2.conf

These urls are correct :
http://www.exemple.com give the content of /var/www/html/index.html
http://app1.exemple.com/app1 give the content of the python app1
http://app2.exemple.com/app2 give the content of the python app2

But it's not what I want.

Therefore the question is : How to have multiple root apps in the same Apache with NamedVirtualHost ?

Thanks in advance

Laurent Trillaud

Graham Dumpleton

unread,
Jul 27, 2011, 3:30:27 AM7/27/11
to mod...@googlegroups.com
The only scenario where you could get what you are seeing is if you
are missing the directive:

NameVirtualHost *:80

to enable name based virtual hosts on port 80.

Without that, all port 80 requests would go to first virtual host
found in order of processing Apache configuration.

If you provide a WSGIScriptAlias inside of VirtualHost it will be
specific to that virtual host and not server wide.

Graham

> --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/modwsgi/-/9ZVBdZKfdbMJ.
> To post to this group, send email to mod...@googlegroups.com.
> To unsubscribe from this group, send email to
> modwsgi+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/modwsgi?hl=en.
>

Laurent Trillaud

unread,
Jul 27, 2011, 3:48:59 AM7/27/11
to mod...@googlegroups.com
Thanks you for your prompt answer.

Unfortunately I have already activated NameVirtualHost.

Here is a sniplet of my httpd.conf

...
Listen 80
ServerName example.com:80
...
LoadModule wsgi_module modules/mod_wsgi.so
...
WSGISocketPrefix /var/run/wsgi
WSGIPythonHome /usr/local/python-2.7
WSGIPythonPath /usr/local/python-2.7/lib/python2.7/site-packages
...
NameVirtualHost *:80
...

Laurent


2011/7/27 Graham Dumpleton <graham.d...@gmail.com>

ltrillaud

unread,
Jul 27, 2011, 3:59:41 AM7/27/11
to mod...@googlegroups.com
Oops there is a syntax error on the mail above
you must read :
ServerName exemple.com

Server name is the same name in virtual host conf file minus the first part

Graham Dumpleton

unread,
Jul 27, 2011, 4:04:10 AM7/27/11
to mod...@googlegroups.com
Verify that the directive is being read by introducing a syntax error
at the same place in the file. For example, add:

XXX

on line immediately after NameVirtualHost.

The run:

apachectl -t

which will validate configuration. It should complain.

If you were to restart Apache it should fail to start.

Also replace your WSGI script file with tests scripts to verify
whether daemon process group being used and what interpreter.Post
results.

http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Embedded_Or_Daemon_Mode
http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Sub_Interpreter_Being_Used

Graham

ltrillaud

unread,
Jul 28, 2011, 3:36:16 AM7/28/11
to mod...@googlegroups.com
Graham

This problem is solved. Your previous post help me to isolate what is going on wsgi and apache.

The problem was on the defaut.conf that must match port 80


First Application default.conf -> static files
<VirtualHost _default_:80>
        DocumentRoot /var/www/html
</VirtualHost>

httpd.conf is still :
...
Listen 80
ServerName exemple.com:80

...
LoadModule wsgi_module modules/mod_wsgi.so
...
WSGISocketPrefix /var/run/wsgi
WSGIPythonHome /usr/local/python-2.7
WSGIPythonPath /usr/local/python-2.7/lib/python2.7/site-packages
...
NameVirtualHost *:80

All works that a charm
Thank you for your help and for your great apache module

Laurent

Reply all
Reply to author
Forward
0 new messages