http/https with Configuration of Apache in "web2py Application Development Cookbook"

197 views
Skip to first unread message

Martin Weissenboeck

unread,
Aug 22, 2012, 3:24:15 PM8/22/12
to web...@googlegroups.com
Ok, I will try to make my question more clear:
I have installing web2py according to the chapter "Setting up a production deployment in Ubuntu"
and I want to redirect http to myapp1 and https to myapp2.

Of course I have tried the file routes.py. It contains:

routers = dict (
    BASE = dict(
        default_application = 'welcome',
        domains = {
            '<my-ip>:80' : 'myapp1/mycontroller',
            '<my-ip>:443' : 'myapp2/mycontroller',
        }
    },
}

I think, Apache converts everything to https, but I don't know why.






2012/8/22 Martin Weissenboeck <mwei...@gmail.com>
A very nice book!
I have executed all steps from the chapter "Setting up a production deployment in Ubuntu" (page 12)
The server works very good, but every request is redirected to https.

https://www.mydomain.com   -> request.is_https==True,  OK?
http://www.mydomain.com becomes https://www.mydomain.com  ->  request.is_https==True


And some other tries:

<p>Your browser sent a request that this server could not understand.<br />
Reason: You're speaking plain HTTP to an SSL-enabled server port.<br />
Instead use the HTTPS scheme to access this URL, please.<br />
The requested URL /secure/default/index was not found on this server.

Every hint is welcome!
Regards, Martin

dhmorgan

unread,
Aug 22, 2012, 9:21:24 PM8/22/12
to web...@googlegroups.com, mar...@weissenboeck.at
I'm wondering what your apache config file looks like for these servers and whether they've both been enabled. The result you reported at the end indicates that your apache server is running fine on port 80, but it's not firing your web2py applications. Perhaps you have not made an entry like 'ServerName www.example.com' that will tell Apache to pick up all traffic looking for said domain. 

Martin Weissenboeck

unread,
Aug 23, 2012, 2:03:01 AM8/23/12
to web...@googlegroups.com
Not exactly.

At first for testing purposes I have changed two lines in  routes.py to


routers = dict (
    BASE = dict(
        default_application = 'welcome',
        domains = {
            '<my-ip>:80' :   'myapp/mycontroller',
            '<my-ip>:443' : 'myapp/mycontroller',
        }
    },
}

I.e. the same controller/function for http and https


There is an answer for
http://xxx.xxx.xxx.xxx/myapp/mycontroller/index  and for
https://xxx.xxx.xxx.xxx/myapp/mycontroller/index

But the http-request is changed to https and the function
https://xxx.xxx.xxx.xxx/myapp/mycontroller/index
is always called. I have checked it also with request.is_https

With
http://xxx.xxx.xxx.xxx:80/myapp/mycontroller/index
I get an error message:
 The requested URL... t was not found on this server.

I have added the following lines to apache2.conf. These lines are copied from "Setting up a production deployment in Ubuntu" (page 12). I have only changed line 1 and 2 to get rid of a warning of apache:

# NameVirtualHost *:80
# NameVirtualHost *:443

<VirtualHost *:80>
    WSGIDaemonProcess web2py user=www-data group=www-data
    WSGIProcessGroup web2py
    WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py

    <Directory /home/www-data/web2py>
    AllowOverride None
    Order Allow,Deny
    Deny from all
    <Files wsgihandler.py>
        Allow from all
    </Files>
    </Directory>

    AliasMatch ^/([^/]+)/static/(.*) /home/www-data/web2py/applications/$1/static/$2

    <Directory /home/www-data/web2py/applications/*/static/>
    Options -Indexes
    Order Allow,Deny
    Allow from all
    </Directory>

    <Location /admin>
    Deny from all
    </Location>

    <LocationMatch ^/([^/]+)/appadmin>
    Deny from all
    </LocationMatch>

    CustomLog /var/log/apache2/access.log common
    ErrorLog /var/log/apache2/error.log
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/self_signed.cert
    SSLCertificateKeyFile /etc/apache2/ssl/self_signed.key

    WSGIProcessGroup web2py

    WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py

    <Directory /home/www-data/web2py>
    AllowOverride None
    Order Allow,Deny
    Deny from all
    <Files wsgihandler.py>
        Allow from all
        </Files>
    </Directory>

    AliasMatch ^/([^/]+)/static/(.*) /home/www-data/web2py/applications/$1/static/$2

    <Directory /home/www-data/web2py/applications/*/static/>
    Options -Indexes
    ExpiresActive On
    ExpiresDefault "access plus 1 hour"
        Order Allow,Deny
    Allow from all
    </Directory>

    CustomLog /var/log/apache2/access.log common
    ErrorLog /var/log/apache2/error.log
</VirtualHost>



2012/8/23 dhmorgan <dharrim...@gmail.com>
--
 
 
 


Reply all
Reply to author
Forward
0 new messages