Redirect http to https via routes.py

290 views
Skip to first unread message

Vinicius Assef

unread,
Dec 6, 2014, 10:44:32 PM12/6/14
to web2py
Is there a way to redirect http to https using routes.py?

I'm running web2py with the following command:
$ python web2py.py --nogui -a adminpassword -c ~/openssl/server.crt -k
~/openssl/server.key -i 0.0.0.0 -p 8000

This way, web2py doesn't accept http connections. It returns a "Bad
Request" error. So, I'd like to make a redirect in routes.py but I
couldn't realize how to make it work.

Any ideia?

Anthony

unread,
Dec 6, 2014, 11:52:45 PM12/6/14
to web...@googlegroups.com
Check out the bottom part of this section. The URL protocol is part of the pattern to be matched, so presumably you can match "http" and rewrite to "https".

Anthony

Vinicius Assef

unread,
Dec 7, 2014, 12:18:34 AM12/7/14
to web2py
I've tried. It stops on rocket. :-(
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Anthony

unread,
Dec 7, 2014, 8:34:46 AM12/7/14
to
If you pass Rocket an SSL certificate, it will only listen on that interface. If you want it to listen on multiple interfaces, you have to use the "--interfaces" argument instead. Something like:

python web2py.py -a adminpassword --interfaces='0.0.0.0:8000;0.0.0.0:8001:~/openssl/server.crt:~/openssl/server.key'

Then you can use routes.py to re-route, or just do a redirect in your app.

Vinicius Assef

unread,
Dec 7, 2014, 5:41:14 PM12/7/14
to web2py
Thank you for your support, Anthony.

Let me say what I was trying:

I'm working with vagrant in my development environment. It's annoying
in every error ticket, change http to https and change port number,
too. The solution to create a tunnel, as described in manual, didn't
make sense because I'm in my dev environment. So, I decided to run my
dev server (inside my vagrant box) always in https.

To achieve it, I'm following your instruction and starting the rocket
server this way:
```
$ python web2py.py --nogui -a '<recicle>'
--interfaces='0.0.0.0:8080;0.0.0.0:8443:/home/vagrant/openssl/server.key:/home/vagrant/openssl/server.crt'
```

Note the sequence: key file first, certificate file, second. ;-)

Besides that I had to configure:
- parameters_8443.py with admin password;
- and port forward in Vagrant file;
- routes.py to redirect traffic from http to https.

Here is a blog post about it in pt_BR:
http://aprenda-python.blogspot.com.br/2014/12/admin-do-web2py-funcionando-em-maquina.html

The same translated to en through Google Translator:
https://translate.google.com/translate?sl=pt&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Faprenda-python.blogspot.com.br%2F2014%2F12%2Fadmin-do-web2py-funcionando-em-maquina.html&edit-text=&act=url

On Sun, Dec 7, 2014 at 11:34 AM, Anthony <abas...@gmail.com> wrote:
> If you pass Rocket an SSL certificate, it will only listen on that
> interface. If you want it to listen on multiple interfaces, you have to use
> the "--interfaces" argument instead. Something like:
>
> python web2py.py -a adminpassword --interfaces
> '0.0.0.0:8000;0.0.0.0:8001:~/openssl/server.crt:~/openssl/server.key'
>
> Then you can use routes.py to re-route, or just do a redirect in your app.
>
> Anthony
>
> On Saturday, December 6, 2014 10:44:32 PM UTC-5, viniciusban wrote:
>>
Reply all
Reply to author
Forward
0 new messages