Hosting question

102 views
Skip to first unread message

Rahul

unread,
Jul 31, 2019, 12:56:36 PM7/31/19
to web2py-users
Hi All,
     This may sound silly but I have a hosting question -  I am already hosting two of my web2py sites on personal VPS server. And I only want anyone who access it to these sites only. I have multiple applications running under same web2py and two of which I use as separate domains. I have default welcome application as well in the application folder. When some access my site they sometimes get redirected to this welcome app. I want to avoid this and the users must only get redirected to the two sites that are hosted. What should I do ?

routers = dict(
        #base router
         BASE=dict(
                          #default_application='Target',
                          domains= { 'www.domain1.co.in' : 'app1',
                                            'www.domain2.in' : 'app2',
           }
    ),
)


Rahul

Jose C

unread,
Jul 31, 2019, 6:05:53 PM7/31/19
to web2py-users

> I want to avoid this and the users must only get redirected to the two sites that are hosted. What should I do ? Two options.

1) remove the default welcome app from your live server (simply delete the directory).
2) Add this key to your BASE dict (which basically tells web2py which apps are allowed to be accessed:
     applications = ['app1', 'app2'],

HTH,
JoseC


Paco Bernal

unread,
Jul 31, 2019, 9:00:25 PM7/31/19
to web2py-users
Hi
Please can you test this url and tell me what you have as result?
http://vps_ip/applications/app1/private/appconfig.ini

Change vps_ip for the ip of your server and app1 for the name of your application (folder name)

Thx

Rahul

unread,
Aug 1, 2019, 6:04:13 AM8/1/19
to web2py-users
Hi Jose,
         I added the line in routes.py  - While it restricts allowing access to other applications like welcome it does not restrict redirection - so in my case it still redirected to welcome application mentioning something is wrong message.

Paco,
    I checked for this "http://vps_ip/applications/app1/private/appconfig.ini" , the problem is my application does not have an appconfig.ini. I started writing it in 2014 or late 2013 so it does not have it as we now have in a default in scaffolding application. I do host the sites on web2py 2.18.5 but that's about it.

Regards,

Rahul

Jose C

unread,
Aug 1, 2019, 7:26:26 AM8/1/19
to web2py-users
>         I added the line in routes.py  - While it restricts allowing access to other applications like welcome it does not restrict redirection - so in my case it still redirected to welcome application mentioning something is wrong message.

Odd.  I have a similar setup to you with multiple domains, 2.18.5, py3 using rocket server.  If I do not place 'welcome' in the 'allowed_apps'  any attempt to get to any page on the welcome app returns a 404 (as expected).
 One thing that may be different... I have additional parameters in routes.py which specifies the default for each app... perhaps in the absence of this it tries to go back to 'welcome'?

routers = dict(
   
# base router
    BASE
= dict(
        domains
={'domain1.com' : 'app1',
                 
'domain2.com' : 'app2',
                 
},
        default_application
= 'app1',

        applications
= ['app1', 'app2'],

        default_function
= 'home',
   
),
    app1
= dict(
        default_language
= 'en',
        languages
= ['en'],
        default_function
= 'home',
   
),
    app2
= dict(
        default_language
= 'en',
        languages
= ['en'],
        default_function
= 'index',
        map_hyphen
= True,
   
),


)

Paco:  Surely appconfig.ini should never be reachable via the url due to the security risks of allowing access to config info?  I paniced for a sec and tried accessing mine with a link like yours but get 404 (as expected).  Are you saying you can see your appconfig.ini, without specifically doing something to expose it, by simply accessing a link the way you formatted it?
 

Rahul Dhakate

unread,
Aug 1, 2019, 7:59:56 AM8/1/19
to web...@googlegroups.com
Hi Jose,
     Have you removed welcome application from web2py applications folder or it still resides there but when accessed gives 404? I am using python 2.7.13 . I will try your settings for routes and get back to you.

In the meantime you may access the sites here that I referred to -
1. www.targetsoft.co.in  - is linked with app1
2. www.artpic.in is linked with app2  ( Just set-it-up yesterday but work remains to be done for a production launch)

Regards,

Rahul

--
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/lvOxb_mb6kQ/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/4cdc72a0-de86-4850-915c-35a5f8eeafd9%40googlegroups.com.

Paco Bernal

unread,
Aug 1, 2019, 8:04:38 AM8/1/19
to web2py-users
Yes, I discovered a few days ago that private folder can be accessed using the vps ip, so I have been playing with host names in appconfig.ini and with apache2 configuration and the only way to stop accessing private folder was adding a new virtualhost in apache for each vps ip with this:

<VirtualHost x.x.x.x:80>
    Redirect 403 /
    ErrorDocument 403 "Sorry, direct IP access not allowed."
    DocumentRoot /dev/null
    UseCanonicalName Off
</VirtualHost>


I use Lets encrypt certificates and redirecting from 80 to 443, and I don't touch virtualhost file in port 80 so for sure, i'm doing something wrong with apache3 and for sure with host names in appconfig.ini

[host]
names = localhost:*, 127.0.0.1:*, *:*, *


Regards

Jose C

unread,
Aug 1, 2019, 8:16:18 AM8/1/19
to web...@googlegroups.com

>
     Have you removed welcome application from web2py applications folder or it still resides there but when accessed gives 404? I am using python 2.7.13 . I will try your settings for routes and get back to you.

Normally I always delete the app, but for testing this issue I left it there, accessed it to check was ok.  Then just set routes.py as above and get 404's when trying to access it.

Both your sites seem to be working well for me.  And from both I can access the welcome app by just typing domain.com/welcome.  Have you made changes to routes.py.  

Important... note that you have to restart the web2py server each time you make a change to routes.py.





Jose C

unread,
Aug 1, 2019, 8:37:37 AM8/1/19
to web2py-users
I use Lets encrypt certificates and redirecting from 80 to 443, and I don't touch virtualhost file in port 80 so for sure, i'm doing something wrong with apache3 and for sure with host names in appconfig.ini

[host]
names = localhost:*, 127.0.0.1:*, *:*, *


That is worrying.  I can only suspect some kind of misconfiguration with apache to be causing this.  Unfortunately I know nothing about apache conf so can't help.  I'd recommend creating a new post with this issue you're having... one of the more knowledgeable folks might be able to help you figure out what is going on.


Rahul Dhakate

unread,
Aug 1, 2019, 9:39:05 AM8/1/19
to web...@googlegroups.com
Hi Jose,
      I did the changes as per your suggestion. Now when I specify a default application it takes me to the same application when I access any domain.
Secondly -
If I specify my domain name without a www. prefix (example: artpic.in)  I am navigated to welcome however the app is not show as its not allowed in routes.py . If I specify the complete address it works properly example: www.artpic.in . Have a look at the screenshot. Also you can check it as I havent reverted the changes yet. Let me know.

My routes.py is

routers = dict(
#base router
BASE=dict(
#default_application='Target',
domains= {
 'www.targetsoft.co.in' : 'Target',
 'www.artpic.in' : 'artpic',
                          },
#default_application = 'Target',
                applications=['Target', 'artpic', ],
default_fucntion = 'index',
),
        Target = dict(

        default_language = 'en',
       languages = ['en'],
        default_function = 'index',
    ),
    artpic = dict(

        default_language = 'en',
        languages = ['en'],
       default_function = 'index',
        map_hyphen = True,
    ),

)


Regards,

Rahul



--
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/lvOxb_mb6kQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
8-1-2019 3-00-06 PM.jpg

Dave S

unread,
Aug 1, 2019, 10:00:01 AM8/1/19
to web2py-users
 
I'd agree that it is an Apache issue.  With my Nginx configuration, I get the expected "invalid function" response from web2py. 

The group wisdom seems to be that Apache setup is arcane and complicated, and Massimo and others explicitly recommend Nginx for production.  If you are constrained to Apache, though, that could be tough.  And I'm no help there.

/dps

Paco Bernal

unread,
Aug 1, 2019, 11:38:26 AM8/1/19
to web...@googlegroups.com
Thank you,

Now it's working as espected.

appconfig.ini

[host]
names = subdomain:*

I removed the virtualhost regarding the dedicated ips and set DocumentRoot in port 80 for my subdomain to /dev/null

Not sure if it's the right way but it's working now without expliciting having a virtualhost for each ip to avoid ip direct access.

About nginx, of course it's much better, but old customs are hard to avoid :)

Regards

Jose C

unread,
Aug 1, 2019, 6:34:58 PM8/1/19
to web2py-users
Strange...

1) First of all, can you confirm this is a routes.py file in the web2py root directory and that there are not any routes.py (app-specific routers) files present in the app directories as well (that could be overriding the main routes.py)?

2) The config I posted is my live config (other then changing domain names and apps to make it easier to read).  It routes to the relevant apps based on the domains as expected, even with the one app set as default.

3) Also in the routes.py code you posted, the default_function key is misspelt as default_fucntion, which would mean it is ignored (although I think web2py looks for 'index' anyway if none specified, but am not 100% certain).

4) Not sure about the www part.  I have a frontend redirect for my www. domains to the normal domain.  But, what if you specify www.domain.com as well as domain.com going to 'app1'.  Haven't tested this but would expect it to work.

5) Earlier I accessed both your sites at site.in/welcome and was served the welcome app.  Now I retried and get the expected error message that it is invalid.  Not sure if that helps.

6) Critical... you must restart the server for any change you make to routes.py to come into effect.  Not sure if you saw this on the last post.



Rahul Dhakate

unread,
Aug 2, 2019, 7:01:35 AM8/2/19
to web...@googlegroups.com
Hi Jose,
        Thanks for getting back - I am using nano for editing routes.py in the live server, it isn't so friendly but gets the job done. Might be one of the reasons for my typo - Here are the answers to rest of the questions - 

1) First of all, can you confirm this is a routes.py file in the web2py root directory and that there are not any routes.py (app-specific routers) files present in the app directories as well (that could be overriding the main routes.py)?
[Rahul] There exists a routes.example.py  (not routes.py) in every application folder - It also exists in web2py\ folder.  Do I need to delete it ? Does it cause issues?

2) The config I posted is my live config (other then changing domain names and apps to make it easier to read).  It routes to the relevant apps based on the domains as expected, even with the one app set as default.
[Rahul]Okay it routes for me tool

3) Also in the routes.py code you posted, the default_function key is misspelt as default_fucntion, which would mean it is ignored (although I think web2py looks for 'index' anyway if none specified, but am not 100% certain).
[Rahul] Yes I rectified that issue yesterday itself as I gave error when accessing sites

4) Not sure about the www part.  I have a frontend redirect for my www. domains to the normal domain.  But, what if you specify www.domain.com as well as domain.com going to 'app1'.  Haven't tested this but would expect it to work.
[Rahul] If I dont specify www part it redirects to /welcome saying "The page isn’t redirecting properly"

5) Earlier I accessed both your sites at site.in/welcome and was served the welcome app.  Now I retried and get the expected error message that it is invalid.  Not sure if that helps.
[Rahul] This helps but still would need a cleaner way to have access to the app mentioned only

6) Critical... you must restart the server for any change you make to routes.py to come into effect.  Not sure if you saw this on the last post.
[Rahul] Yes this was done for every change I did.. I restarted Apache after changes to routes.py to reload it. 


Regards,

Rahul


--
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/lvOxb_mb6kQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Jose C

unread,
Aug 2, 2019, 8:23:19 AM8/2/19
to web2py-users
Hi Rahul,

ok,..
1) no the routes.examples.py files don't cause any problems.
4) Can you make sure that both 'www.domain.in': 'app1' as well as 'domain.in': 'app1' are specified in the domains key of the BASE dict?  I would hope this finally resolves your issue.

I don't have any experience at all with Apache and if point 4) above doesn't resolve your issue then the Apache config is where I would be inclined to look. Unfortunately I'm unable to help you with that, sorry.

Jose

Rahul Dhakate

unread,
Aug 2, 2019, 8:40:05 AM8/2/19
to web...@googlegroups.com
Hi Jose,
        Thank you !! That worked ... the point #4 resolved that issue. So now no need to work with Apache and all is working well. Thanks a million!!
artpic.in and targetsoft.co.in work fine now.

Regards,

Rahul

--
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/lvOxb_mb6kQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Jose C

unread,
Aug 2, 2019, 10:12:59 AM8/2/19
to web2py-users
Glad to have helped.

Cheers,


On Friday, 2 August 2019 09:40:05 UTC+1, Rahul wrote:
Hi Jose,
        Thank you !! That worked ... the point #4 resolved that issue. So now no need to work with Apache and all is working well. Thanks a million!!
artpic.in and targetsoft.co.in work fine now.

Regards,

Rahul

On Fri, Aug 2, 2019 at 1:53 PM Jose C <houdini...@gmail.com> wrote:
Hi Rahul,

ok,..
1) no the routes.examples.py files don't cause any problems.
4) Can you make sure that both 'www.domain.in': 'app1' as well as 'domain.in': 'app1' are specified in the domains key of the BASE dict?  I would hope this finally resolves your issue.

I don't have any experience at all with Apache and if point 4) above doesn't resolve your issue then the Apache config is where I would be inclined to look. Unfortunately I'm unable to help you with that, sorry.

Jose

--
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/lvOxb_mb6kQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages