thebjorn
thebjorn

Reputation: 27311

How do I do multi-domain https with mod_wsgi?

I'm a developer and a bit of an apache novice and I'm trying to transition a bunch of our Django https servers to mod_wsgi, which previously used mod_python:

<VirtualHost *:443>
    ServerName *.example.com

    SSLEngine On

    SSLCertificateFile /etc/ssl/star_example_com.crt
    SSLCertificateKeyFile /etc/ssl/star_example_com.key
    SSLCertificateChainFile /etc/ssl/DigiCertCA.crt

    UseCanonicalName Off
    VirtualDocumentRoot /var/www/%0

    <Directory "/var/www/foo.example.com">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE example.foo.settings
        PythonPath "['/home/django'] + sys.path"
        PythonDebug on
    </Directory>

    <Directory "/var/www/bar.example.com">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE example.bar.settings
        PythonPath "['/home/django'] + sys.path"
        PythonDebug on
    </Directory>
</VirtualHost>

This allows us to run several https sites on the same physical server (ip). Adding a new https host simply involves adding a new <Directory> section, and creating the corresponding directory under /var/www/.

The closest I've gotten is by using

<Directory "/var/www/bar.example.com">
    SetHandler wsgi-script
    Options ExecCGI
</Directory>

and creating /var/www/bar.example.com/bar.wsgi, then I can access urls like https://bar.example.com/bar.wsgi/...rest..of..path..

I haven't been able to find a directive (that can be used inside <Directory>) that is equivalent to WSGIScriptAlias when the target is a file-path, like we're using for the non-https sites:

<VirtualHost *:80>
    ServerName bar.example.com
    WSGIScriptAlias / /home/venv/upgrade/example/bar/bar.wsgi
    <Directory "/var/www/bar/">
        Order deny,allow
        allow from all
    </Directory>
</VirtualHost>

Which allows us to go to http://bar.example.com/...rest..of..path.. (ie. no bar.wsgi prefix).

Is it possible to get rid of the bar.wsgi part in the https url?

[Solution:] (based on @GrahamDumpleton's link):

<Directory /var/www/bar.example.com/>
    Options ExecCGI Indexes FollowSymlinks
    AddHandler wsgi-script .wsgi
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /bar.wsgi/$1 [QSA,PT,L]

    Order allow,deny
    Allow from all
</Directory>

works beautifully.

Upvotes: 0

Views: 565

Answers (1)

Graham Dumpleton
Graham Dumpleton

Reputation: 58523

This is covered in:

http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive

See the bit towards the end of the section where shows use of mod_rewrite and an application wrapper to do fixups of SCRIPT_NAME.

Upvotes: 2

Related Questions