apache+mod_wsgi, redirect to https

1,056 views
Skip to first unread message

refreegrata

unread,
May 31, 2011, 1:15:14 PM5/31/11
to Django users
Hello guys and girls. I have a question. In my apache configuration I
have this:

WSGIScriptAlias /misite "rute_to_file.wsgi"

The users can access from:

http://mysite/
and
https://mysite/

I need to enable the access only from "https://mysite/". Every access
from "http://mysite/" must to be redirected to "https://mysite/". How
can i do this?

Normally I use mod_rewrite, and thats works fine for the static files,
php, etc, but I don't have idea how do this with mod_wsgi.

Additionaly, can be very helpful if somebody now how configure an
"Require Auth" with mod_wsgi.

Sometime ago somebody asked the same in stackoverflow, without get
answers.

Thanks for read, and sorry for my poor english.

Michael Scovetta

unread,
May 31, 2011, 1:33:16 PM5/31/11
to django...@googlegroups.com
I usually set up two virtual hosts, one listening on port 80 and the other on 443. The virtual host listening on port 80 just redirects to the other one:

<VirtualHost 1.2.3.4:80>
    ServerAdmin ad...@example.com
    ServerName domain.com

    HostnameLookups Off
    UseCanonicalName On
    ServerSignature Off

    Redirect / https://domain.com/
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on

    ServerAdmin ad...@example.com
    ServerName domain.com

    HostnameLookups Off
    UseCanonicalName On
    ServerSignature Off

    WSGIScriptAlias / /opt/apache/wsgi_start.py
    WSGIPassAuthorization On
    ...
</VirtualHost>

I haven't tried it, but would think that you could use mod_rewrite along with mod_wsgi, but it's possible that WSGI gets called first automagically.

Hope this helps!

Mike

refreegrata

unread,
May 31, 2011, 1:46:17 PM5/31/11
to Django users
Thanks men, I did this:
--------------------------
<VirtualHost *:80>
<Directory />
...
...
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</Directory>
...
</VirtualHost>
------------------------
Works ok to me. Now I must to test the "Require Auth".
Bye.


On 31 mayo, 13:33, Michael Scovetta <michael.scove...@gmail.com>
wrote:
> I usually set up two virtual hosts, one listening on port 80 and the other
> on 443. The virtual host listening on port 80 just redirects to the other
> one:
>
> <VirtualHost 1.2.3.4:80>
>     ServerAdmin ad...@example.com
>     ServerName domain.com
>
>     HostnameLookups Off
>     UseCanonicalName On
>     ServerSignature Off
>
>     Redirect /https://domain.com/
Reply all
Reply to author
Forward
0 new messages