web2py multiple domains on nginx + gunicorn

119 views
Skip to first unread message

Áureo Dias Neto

unread,
Jul 1, 2019, 9:23:30 AM7/1/19
to web2py-users
Good morning group,

I'm using web2py on nginx + gunicorn, I currently have two applications with two different domains, one for each web2py application ..

Each domain points to my ip in AWS and nginx, each domain has a file in nginx with its settings and server_name corresponding to its domain with location pointing to / web2py / applications

My routes.py file follows the pattern:

routers = dict (
    BASE = dict (
        domains = {
            'exampleapp.com': 'exampleapp',
            'anotherexample.com': 'anotherexample',
        }
    ),
)

however, whenever you access exampleapp.com or any other domain listed there, I'm redirected to exampleapp.com/welcome

I can only run an app with the following configuration in the routes.py file

routers = dict (
    BASE = dict (
        default_application = 'exampleapp',
        domains = {
            'exampleapp.com': 'exampleapp',
            'anotherexample.com': 'anotherexample',
        }
    ),
)

so both exampleapp.com and anotherexample.com redirect to exampleapp.

How to proceed?
Hugs

Jim S

unread,
Jul 1, 2019, 11:07:26 AM7/1/19
to web2py-users
My routes.py with multiple domains.  I don't really see any difference.  Are you sure you're using the right domains?  I also have entries in there for when I'm testing from my local network because the domain is going to look different.

#!/usr/bin/python
# -*- coding: utf-8 -*-


# default_application, default_controller, default_function
# are used when the respective element is missing from the
# (possibly rewritten) incoming URL
#
default_application
= 'app1'    # ordinarily set in base routes.py
default_controller
= 'default'  # ordinarily set in app-specific routes.py
default_function
= 'index'      # ordinarily set in app-specific routes.py


routers
= dict(BASE=dict(domains={'www.url1.com': 'app1',
                                 
'www.url2.com': 'app2',
                                 
'localhostname1': 'app1',
                                 
'localhostname2': 'app2'}), )


routes_onerror
= [
   
('app1/*', '/app1/default/error_handler')
]

Áureo Dias Neto

unread,
Jul 1, 2019, 11:23:13 AM7/1/19
to web...@googlegroups.com
You have routes.py only in web2py folder? 

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/NOIo7F3Ztd8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/aa588fcc-b4b9-4389-a6a0-519052e31f90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jim Steil

unread,
Jul 1, 2019, 11:26:07 AM7/1/19
to web...@googlegroups.com

Alex Beskopilny

unread,
Jul 1, 2019, 12:03:35 PM7/1/19
to web2py-users


понедельник, 1 июля 2019 г., 16:23:30 UTC+3 пользователь Áureo Dias Neto написал:

.....
for me works
1 up second gunicorn
2  dom2.conf
upstream gunidom2 { server unix:/home/w2p/var/guni-dom2.sock fail_timeout=0; }

server {

        listen xx.yy.zz.ww:443 ssl http2;
         server_name dom2.ru;
         add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";

          add_header Allow "GET, POST, HEAD, DELETE" always;
          if ( $request_method !~ ^(GET|POST|HEAD|DELETE)$ ) {
              return 444;
         }

ssl_certificate /etc/letsencrypt/live/dom2.ru/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/dom2.ru/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/dom2.ru/chain.pem;

resolver 127.0.0.1 valid=86400 ipv6=off;

ssl on;

......
}
......
location / {

                try_files $uri @proxy_to_gunidom2;
        }

location @proxy_to_gunidom2 {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Ssl on;
                proxy_set_header Host  dom2.ru;
                proxy_redirect off;

add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block;";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

                proxy_set_header        X-Forwarded-By    $server_addr:$server_port;
                proxy_set_header        X-Forwarded-Proto $scheme;
                proxy_set_header        X-Real-IP         $remote_addr;


                proxy_pass http://gunidom2;
             rewrite ^/$ /dom2 last;
        }


Áureo Dias Neto

unread,
Jul 1, 2019, 1:18:54 PM7/1/19
to web...@googlegroups.com
Attached, my configuration files:

-nginx.conf (nginx main file)
-site1 (domain 1 that should be routed to app2 from web2py, I just
changed names for privacy reasons)
-site2 (domain 2 that should be routed to app2 from web2py, I just
changed names for privacy reasons)
> --
> 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 a topic in the Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/NOIo7F3Ztd8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/0e914b35-a6a1-49cb-adf4-1cd4b1ed41d0%40googlegroups.com.
nginx.conf
site1.net
site2.net

Alex Beskopilny

unread,
Jul 1, 2019, 2:55:18 PM7/1/19
to web2py-users

start second guicorn
You have to run your projects on different ports like firsrone on 8000 and secondone on 8001. Then in nginx conf, in place of location /, you have to write location /firstone/ and proxy pass this to port 8000 and then write same location object for second one as location /secondone/ and proxy pass it to port 8001.


some example
http://michal.karzynski.pl/blog/2013/10/29/serving-multiple-django-applications-with-nginx-gunicorn-supervisor/


понедельник, 1 июля 2019 г., 16:23:30 UTC+3 пользователь Áureo Dias Neto написал:
Good morning group,

Val K

unread,
Jul 1, 2019, 3:26:33 PM7/1/19
to web2py-users
I'm not a pro in nginx but if you set proxy_set_header Host 192.168.7.2; how does web2py know about www.domain1.net? Maybe it should be proxy_set_header Host $host?

Áureo Dias Neto

unread,
Jul 1, 2019, 8:16:10 PM7/1/19
to web...@googlegroups.com
Val K you're right, that's done! thanks

Em seg, 1 de jul de 2019 às 16:26, Val K <valq...@gmail.com> escreveu:
>
> I'm not a pro in nginx but if you set proxy_set_header Host 192.168.7.2; how does web2py know about www.domain1.net? Maybe it should be proxy_set_header Host $host?
>
> --
> 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 a topic in the Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/NOIo7F3Ztd8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/e5be16a6-44de-4ec7-bed0-3f55d69cfad9%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages