From: SourceForge.net <no...@so...> - 2005-04-12 06:46:47
|
Feature Requests item #1159471, was opened at 2005-03-08 17:40 Message generated for change (Comment added) made by sdeasey You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=719009&aid=1159471&group_id=130646 Category: C-API Group: None >Status: Closed >Resolution: Accepted Priority: 5 Submitted By: Vlad Seryakov (seryakov) Assigned to: Vlad Seryakov (seryakov) Summary: Virtual Hosting Initial Comment: Okay, i did some digging and testing, looks working and much simpler. I tried to simplify default AS 4.x virtual hosting and added pageroot virtual hosting, simple way to use different pagetroots on the same server. The change vor default virtual hosting is: no defaultserver anymore, the server who registered virtual hosts is default server, so nssock is loaded in the default server, other than that virtual servers are defined the same way. One thing i left is to chamge ns_info pageroot to use Ns_GetConn() and then if exists use connPtr->pageroot, but this is simple change if you approve current virtual hosting patch. Here is the nsd.tcl config example: ns_section "ns/server/${server}/module/nssock/servers" ns_param test vlad.seryakov.com ns_param test vlad.seryakov.com:80 ns_section "ns/server/${server}/module/nssock/pageroots" ns_param ${home}/html/test vlad.seryakov.com ns_param ${home}/html/test vlad.seryakov.com:80 ---------------------------------------------------------------------- >Comment By: Stephen Deasey (sdeasey) Date: 2005-04-12 00:46 Message: Logged In: YES user_id=87254 Ok, this is now in CVS. ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-04-03 20:40 Message: Logged In: YES user_id=184124 Patch worked for me ---------------------------------------------------------------------- Comment By: Stephen Deasey (sdeasey) Date: 2005-04-03 18:56 Message: Logged In: YES user_id=87254 I found some errors in the previous patch, so here's another one. I wouldn't be so conservative, except an error here would be a big security hole. I've written some tests. I;d appreciate it if you'd take a look and see if this looks alright? If you're happy that this looks reasonable, I'll commit it. I've fixed the hostprefix config that you noted. I also changed Ns_ConnLocationAppend() and Ns_ServerPath()/Ns_PagePath() to always return a valid result. The driver's staticaly configured location is used if a callback fails. I felt it was just too ugly to have to check the return every time. I'm thinking maybe there needs to be some kind of common Ns_HostIsValid() routine... ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-04-01 07:12 Message: Logged In: YES user_id=184124 Can we commit this patch, i need to replace one of my virtual hosting servers and i would give it a try with new patch. ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-27 18:59 Message: Logged In: YES user_id=184124 One notice, hostpreix bt default is vhost, not empty, would be better to have it empty. ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-27 18:55 Message: Logged In: YES user_id=184124 Yes, this worked for me, if Zoran does not mind, you can commit it. ---------------------------------------------------------------------- Comment By: Stephen Deasey (sdeasey) Date: 2005-03-27 07:25 Message: Logged In: YES user_id=87254 The new serverdir is for storing files associated with a server (or virtual host) which are not made public via the pagedir. So, things like uploads, auto-generated data, caches etc. This will contain only the pages directory by default, because the server doesn't do anything interesting by default. I've attached a new patch which makes the serverdir and pagedir fully customisable. Here are the possible config settings: ns_section "ns/server/${servername}/fastpath" ns_param serverdir /srv # default: $home/servers/$servername ns_param pagedir pages #ns_param pageroot pages # depreciated ns_section "ns/server/${servername}/vhost" ns_param enabled false ns_param hostprefix vhosts #default "" ns_param hosthashlevel 3 ns_param stripport true ns_param stripwww true I've added path hashing, which hashes the hostname so that they are spread accross multiple directories. e.g. foo.com -> ./f/o/o/pages a.com -> ./a/_/_/pages I've also added a -host switch to the ns_serverpath and ns_pagepath commands so that tool can be written which setup the necessary directories. Does this look ok? ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-17 21:26 Message: Logged In: YES user_id=184124 On the other hand if it will be possible to configure/rename "servers/" and "pages/" parts or omit them completely i would be happy with this patch. ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-14 07:48 Message: Logged In: YES user_id=184124 The problem i see with this patch, it will break all my AS installations, because it assumes that every servers is under servers/ direcotory and pageroot is awlays named pages/. I my on-server installs i do not have this complex directory structure, i have html/ under ns_info home and pageroot is set in the nsd.tcl. Also, what is the point of ServerRoot dir, we have PageRoot already, if it is set into absolute path other apps use ns_info pageroot? As i understand, under ServerRoot there is only pages difrectory? Why not to use pageroot directly? ---------------------------------------------------------------------- Comment By: Stephen Deasey (sdeasey) Date: 2005-03-14 07:05 Message: Logged In: YES user_id=87254 Oh, forgot to mention. It depends on the Tcl Callbacks patch. ---------------------------------------------------------------------- Comment By: Stephen Deasey (sdeasey) Date: 2005-03-14 07:03 Message: Logged In: YES user_id=87254 I've added the patch naviserver-4.0.10-server-root-vhost.patch. It adds the following new routines: Ns_ServerPath() Ns_PagePath() Ns_SetServerRootProc() Ns_ConnLocationAppend() Ns_SetConnLocationProc() NsServerRoot() NsPageRoot() ns_serverpath ?pathSegment ...? ns_pagepath ?pathSegment ...? ns_serverrootproc script ?arg? ns_locationproc script ?arg? And the following new configuration options: ns_section "ns/server/${servername}/vhost" ns_param enabled false ns_param prefix "" ns_param pagedir pages # overides fastpath/pageroot ns_param stripwww true ns_parma stripport true This version of host header based virtual hosting which depends on the existance of the pages directory is a superset of the functionality provided by a static configuration. Applications which call Ns_ConnLocation() will need to be modified to call Ns_ConnLocationAppend() or they will not be vhost aware. I've reinstated the depreciated proc Ns_SetConnLocationProc() and changed it's signature. It dissapeared from ns.h almost 5 years ago, then reappreared ~2.5 years ago. I don't think this will be a problem. In turn, I've depreciated the Ns_SetLocationProc(). It compiles and the server runs. I haven't had time to test it. Does this look acceptable? ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-12 17:41 Message: Logged In: YES user_id=184124 Just to consider the possibility, instead of mallocing pageroot/location, by default it can use sockPtr->pageroot/sockPtr->location, then when ns_conn pageroot newpageroot called, it will set connPtr->pageroot with malloced string and ns_conn pageroot will check and return it instead of sockPtr->pageroot. This way, no overhead at conn queue and still new pageroot/location can be set in Tcl ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-12 17:02 Message: Logged In: YES user_id=184124 That is the probem with nssock, it is actually an extender of the driver but still somehow kept independent. nssock itself is useless without driver and only used to bind to more than one address for different servers. it could be moved in the core but the problem will be how to define more than once instance. malloc are overhead indeed, but once copied they can be used independently and canbe set in Tcl by using ns_conn location newLocation or ns_conn pageroot newPageroot. In this case they should be a copies. Just do not make mass virtual hosting the only virtual hosting way, being able to change pageroot in the Tcl/C give developer more flexibility if required. For simple cases, mass virtual hosting is okay. ---------------------------------------------------------------------- Comment By: Stephen Deasey (sdeasey) Date: 2005-03-12 16:48 Message: Logged In: YES user_id=87254 I'm not keen at all on adding virtual hosting to the nssock driver. There's nothing HTTP specific about the nssock dirver and I'd like to keep it that way. There are a couple of problems with the other proposed solution. The paired functions Ns_SetLocationProc()/Ns_ConnSetLocationProc() etc. seems excessive, and the enforced malloc()ing at runtime of the location and pageroot strings is an unwelcome overhead. Using Tls storage is clever but pretty ugly. I think dstrings are the way to go here. I'm not sure Tls is safe in this implementation. The same dstring is used for location and pageroot strings, so it depends what the caller decides to do with the result and in what order, whether or not one overwrites the other. I would like to explore adding mas virtual hosting into the core. Let me work up a patch, I think I can get to this this weekend... ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-12 14:57 Message: Logged In: YES user_id=184124 Attached is nssock with virtual hosting patch ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-12 13:39 Message: Logged In: YES user_id=184124 Actually, vhost can be combined with nssock, if options given it will enable virtual hosting, if not works as regular sock driver. This way it is always with the core and at the same time independent. ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-10 14:38 Message: Logged In: YES user_id=184124 If loaded, vhost module works as Stephan suggested, strips port/host and usesd pageroot if other root is not specified. ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-10 14:37 Message: Logged In: YES user_id=184124 There is new patch with Stephans corrections/additions. I think we can provide core module for virtual hosting, i called it nsvhost and we can extend this module to do all sorts of hosting. ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-10 11:53 Message: Logged In: YES user_id=184124 And keeping port and www. is sometimes necessary, you can do virtual hosting by port only, IDT does that for example, and many sites work without www. prefix, just stripping them by default may not be appropriate. ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-10 11:24 Message: Logged In: YES user_id=184124 >Looks good. However, isn't ns_conn pageroot >unneccessary? For templating engines ns_info pageroot is the only way to figure out the root, UrlToFile works for fastpath only. >Would it be better to have the servers and pageroot config >in one section, to avoid duplication? They are mutually exclusive, that's why i put them in different sections, if full virtual server is set, pageroots are ignored, this is for AOL like virtual hosting with different servers(rare situation though). So in most cases pageroots will be used only, thus only one simple syntax. As for PageRoot and ServerRoot, i think this is a little cofusing. Currently, pageroot returns full path and whoever calls pageroot assumes that it will return full path. Virtual hosting using directories as hostnames is what i am currently using with vhost module and i think it can be included as a standard feature for easy virtualhosting solutions. I do not think this should be the ONLY virtual hosting solution, everybody can write their own modules using SetLocation/SetPageRoot procs or register filter which will set pageroot for each connection. Let me prepare another patch-set with your suggestions included . ---------------------------------------------------------------------- Comment By: Stephen Deasey (sdeasey) Date: 2005-03-10 01:00 Message: Logged In: YES user_id=87254 Looks good. However, isn't ns_conn pageroot unneccessary? Would it be better to have the servers and pageroot config in one section, to avoid duplication? ns_section "ns/server/${server}/module/nssock/servers" ns_param example.com exampleserver ns_param foo.example.com "exampleserver ${home}/whatever" Here, the first entry maps the example.com host to the exampleserver and uses it's default pageroot. The second entry supplies a new pageroot. How about mass virtual hosting, i.e. where you don't have to explicitly configure each host header to pageroot mapping, but construct the pageroot from the host heafer at runtime? I've attached the file nsmassvhost.c which implements the above. It uses the hooks Ns_PageRootProc and Ns_LocationProc which would be unneccessary if the functionality was included as standard. It trims the port and any leading 'www.' from the host header. It would be nice to have this for the static mapping also, as at the moment to be robust you often need 4 mappings for each virtual host. It also uses the function Ns_ServerPath(). The idea here is to introduce the concept of the virtual server root as a distinct location in the file system, where the pageroot is a location below that. I want to change this so that the serverroot is dynamic and based on the host header (when configured), and the pageroot is simply the serverroot with "/pages" (or whatever is configured) appended. It would look something like this: /srv/server1/pages /srv/server1/example.com/pages /srv/server1/example.com/cache The first path is the default or non-virtual hosted case. server1 is a server defind in the config file and has it's own private tcl library. The second path is the pageroot of a virtual host. The third is an example of some data which is specific to the example.com virtual host. So, without virtual hosts: Ns_ServerRoot() -> /srv/server1 Ns_PageRoot() -> /srv/server1/pages With virtual hosts (and called in the context of a conn thread): Ns_ServerRoot() -> /srv/server1/example.com Ns_PageRoot() -> /srv/server1/example.com/pages The advantage of this system is that you don't have to restart your server every time you add or remove a virtual host. There is also a convenient location to store data associated with both virtual servers and virtual hosts. Easy to backup, remove, etc. I haven't had time to look at how this would be integrated into what you've got here, maybe at the weekend. Feel free to take a shot at though :-) Does the scheme outlined above make sense to you? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=719009&aid=1159471&group_id=130646 |