routing problem nginx + uwsgi

165 views
Skip to first unread message

keiser1080

unread,
Jul 3, 2013, 11:08:06 AM7/3/13
to web...@googlegroups.com
Hi all,

I need to configure a webserver  with multiples web2py instances.
Each instance is linked to a python virtualenv in home folder of each users (3 users)
  • I have no access to the dns and the proxy
  • and can't ask to modify the dns and webproxy
  • and can't install a local dns server


the server has an intranet domain name, myserver.mydomain
i need for example.
myserver.mydomain/myuser1/ to point on the root of the user1 web2py instance
myserver.mydomain/myuser1/app1/ to point on the app1 of the user1 web2py instance
myserver.mydomain/myuser2/ to point on the root of the user2 web2py instance
myserver.mydomain/myuser2/app1/ to point on the app1 of the user2 web2py instance
ect...

how to configure nginx and web2py router for each instances?

I have try
/etc/nginx/sites-available/web2py
server
{
        listen          
80;
        server_name     $hostname
;
       
###to enable correct use of response.static_version
       
#location ~* /(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
       
#    alias /home/www-data/web2py/applications/$1/static/$2;
       
#    expires max;
       
#}
       
###

       
###if you use something like myapp = dict(languages=[en, it, jp], default_language=en) in your routes.py
       
#location ~* /(\w+)/(en|it|jp)/static/(.*)$ {
       
#    alias /home/www-data/web2py/applications/$1/;
       
#    try_files static/$2/$3 static/$3 =404;
       
#}
       
###
        location
~* /(\w+)/static/ {
           
#root /home/www-data/web2py/applications/;
            root
/home/user1/Vhome/Vweb2py/web2py/applications/;
           
#remove next comment on production
           
#expires max;
           
### if you want to use pre-gzipped static files (recommended)
           
### check scripts/zip_static_files.py and remove the comments
           
# include /etc/nginx/conf.d/web2py/gzip_static.conf;
           
###
       
}
        location
/user1 {
           
#uwsgi_pass      127.0.0.1:9001;
            uwsgi_pass      unix
:///tmp/web2py.socket;
            include         uwsgi_params
;
            uwsgi_param     UWSGI_SCHEME $scheme
;
            uwsgi_param     SERVER_SOFTWARE    nginx
/$nginx_version;

           
###remove the comments to turn on if you want gzip compression of your pages
           
# include /etc/nginx/conf.d/web2py/gzip.conf;
           
### end gzip section

           
### remove the comments if you use uploads (max 10 MB)
           
#client_max_body_size 10m;
           
###
            uwsgi_param SCRIPT_NAME
/user1;
            uwsgi_modifier1
30;
       
}
}
server
{
        listen
443 default_server ssl;
        server_name     $hostname
;
        ssl_certificate        
/etc/nginx/ssl/web2py.crt;
        ssl_certificate_key    
/etc/nginx/ssl/web2py.key;
        ssl_prefer_server_ciphers on
;
        ssl_session_cache shared
:SSL:10m;
        ssl_session_timeout
10m;
        ssl_ciphers ECDHE
-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA;
        ssl_protocols
SSLv3 TLSv1;
        keepalive_timeout    
70;
        location
/ {
           
#uwsgi_pass      127.0.0.1:9001;
            uwsgi_pass      unix
:///tmp/web2py.socket;
            include         uwsgi_params
;
            uwsgi_param     UWSGI_SCHEME $scheme
;
            uwsgi_param     SERVER_SOFTWARE    nginx
/$nginx_version;
           
###remove the comments to turn on if you want gzip compression of your pages
           
# include /etc/nginx/conf.d/web2py/gzip.conf;
           
### end gzip section
           
### remove the comments if you want to enable uploads (max 10 MB)
           
#client_max_body_size 10m;
           
###
       
}
       
## if you serve static files through https, copy here the section
       
## from the previous server instance to manage static files

}

and routes.py

# -*- 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 = 'init'    # 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
BASE = 'user1'
routers = dict(
    BASE = dict(
        domains = {
            'jeraweb1.bc': 'aut',
            'jeraweb1.bc/user1/welcome': 'welcome',
            'jeraweb1.bc/user1/aut': 'aut',
            'jeraweb1.bc/user1/aut2': 'aut2',

        }
    ),
)


but that don't work.

Any idea?


Jonathan Lundell

unread,
Jul 3, 2013, 2:37:42 PM7/3/13
to web...@googlegroups.com
On 3 Jul 2013, at 8:08 AM, keiser1080 <iac...@gmail.com> wrote:
and routes.py

# -*- 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 = 'init'    # 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
BASE = 'user1'
routers = dict( 
    BASE = dict( 
        domains = {
            'jeraweb1.bc': 'aut',
            'jeraweb1.bc/user1/welcome': 'welcome',
            'jeraweb1.bc/user1/aut': 'aut',
            'jeraweb1.bc/user1/aut2': 'aut2', 

        } 
    ), 
)


but that don't work.

Any idea?

The parametric router doesn't allow paths as part of the domain name in the domains section. You'll need to use the pattern-based router for that.

Alternatively, you might want to look at specifying 'user1' as a path_prefix, although that would prevent URL() from generating URLs that did not have 'user1' prefixed.

Icham Achtir

unread,
Jul 3, 2013, 3:38:06 PM7/3/13
to web...@googlegroups.com

Thanks can you give my an example ?

Jonathan Lundell

unread,
Jul 3, 2013, 4:01:30 PM7/3/13
to web...@googlegroups.com
On 3 Jul 2013, at 12:38 PM, Icham Achtir <iac...@gmail.com> wrote:

Thanks can you give my an example ?




For path_prefix, you mean? Just specify path_prefix = 'user1' in your router. The router will strip that from incoming URLs, so the rest of the URL can include an application.

routers = dict( 
    BASE = dict( 
        path_prefix = 'user1',
        default_application = 'aut',
    ), 
)

Specifying the default application as aut ought to let you get away with incoming URLs that aren't prefixed by 'user1'.

Icham Achtir

unread,
Jul 3, 2013, 4:13:29 PM7/3/13
to web...@googlegroups.com
thanks you.

I mean an example of the  pattern-based router.
Before I leave my office, I have try tu use the  pattern-based router.
And i don't find the solution, for example when i request the url mydomain/user1/myApp that work but when I click on home 
Home point to mydomain/user1/myApp/user1/myApp.
I give an other try  and home point to mydomain/myApp
So i think the routes_in is correct but the routes_out is incorrect
I am @home now. 



2013/7/3 Jonathan Lundell <jlun...@pobox.com>

--
 
---
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/ybpY_llWT5s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jonathan Lundell

unread,
Jul 3, 2013, 4:20:54 PM7/3/13
to web...@googlegroups.com
On 3 Jul 2013, at 1:13 PM, Icham Achtir <iac...@gmail.com> wrote:
thanks you.

I mean an example of the  pattern-based router.
Before I leave my office, I have try tu use the  pattern-based router.
And i don't find the solution, for example when i request the url mydomain/user1/myApp that work but when I click on home 
Home point to mydomain/user1/myApp/user1/myApp.
I give an other try  and home point to mydomain/myApp
So i think the routes_in is correct but the routes_out is incorrect
I am @home now. 

Someone else will have to help with that. It's tricky.
Reply all
Reply to author
Forward
0 new messages