Claes Wikstrom-2 wrote:
>
> Christian S wrote:
>> You might want to redirect one of the domains to the other instead of
>> having multiples name for the same site.
>
> I agree, using it with redirs is better. This is what I've been
> doing for that precise problem with multiple names for the same
> domain.
>
> Also noteable here is the configuration directive:
>
> pick_first_virthost_on_nomatch (read in the manpage what it does)
>
> /klacke
>
Adding vhost alias support is pretty trivial.. heres a quick patch that does
it and includes *.servername.com support
to use it add a serveraliases line in your <server> section specifiying one
or more aliases... eg:
<server servername.com>
serveraliases = *.servername.com
port = 80
docroot = www/
</server>
Index: src/yaws.erl
===================================================================
RCS file: /cvsroot/erlyaws/yaws/src/yaws.erl,v
retrieving revision 1.105
diff -u -r1.105 yaws.erl
--- src/yaws.erl 5 Nov 2006 21:20:28 -0000 1.105
+++ src/yaws.erl 6 Nov 2006 11:39:33 -0000
@@ -128,6 +128,8 @@
D#sconf.listen),
servername = lkup(servername, SL,
D#sconf.servername),
+ serveraliases = lkup(serveraliases, SL,
+ D#sconf.serveraliases),
ets = lkup(ets, SL,
D#sconf.ets),
ssl = lkup(ssl, SL,
Index: src/yaws_config.erl
===================================================================
RCS file: /cvsroot/erlyaws/yaws/src/yaws_config.erl,v
retrieving revision 1.108
diff -u -r1.108 yaws_config.erl
--- src/yaws_config.erl 18 Oct 2006 13:51:34 -0000 1.108
+++ src/yaws_config.erl 6 Nov 2006 11:39:34 -0000
@@ -626,6 +626,10 @@
C2 = ?sc_set_add_port((C#sconf{servername = Name}),false),
fload(FD, server, GC, C2, Cs, Lno+1, Next);
+ ["serveraliases", '=', Name] ->
+ C2 = C#sconf{serveraliases = string:tokens(Name, " ")},
+ fload(FD, server, GC, C2, Cs, Lno+1, Next);
+
["docroot", '=', Rootdir | XtraDirs] ->
RootDirs = lists:map(
fun(R) -> filename:absname(R)
Index: src/yaws_server.erl
===================================================================
RCS file: /cvsroot/erlyaws/yaws/src/yaws_server.erl,v
retrieving revision 1.311
diff -u -r1.311 yaws_server.erl
--- src/yaws_server.erl 18 Oct 2006 14:18:46 -0000 1.311
+++ src/yaws_server.erl 6 Nov 2006 11:39:36 -0000
@@ -936,17 +936,29 @@
%% compare servername and ignore any optional
%% :Port postfix
-comp_sname([$:|_], _) -> true;
-comp_sname(_, [$:|_]) -> true;
-comp_sname([H|T], [H|T1]) -> comp_sname(T,T1);
-comp_sname([],[])-> true;
-comp_sname(_,_)-> false.
+
+comp_sname(H, S, A) ->
+ case comp_sname(H, S) of
+ true -> true;
+ false -> comp_aliases(H, A)
+ end.
+comp_sname(H, [$*, $.|S]) -> lists:suffix(remove_port(S), remove_port(H));
+comp_sname(H, S) -> remove_port(H) == remove_port(S).
+
+remove_port(S) -> hd(string:tokens(S, ":")).
+
+comp_aliases(_, []) -> false;
+comp_aliases(Host, [H|T]) ->
+ case comp_sname(Host, H) of
+ true -> true;
+ false -> comp_aliases(Host, T)
+ end.
pick_sconf(GC, H, [SC|_Group], ssl) ->
- case comp_sname(H#headers.host, SC#sconf.servername) of
+ case comp_sname(H#headers.host, SC#sconf.servername,
SC#sconf.serveraliases) of
true ->
SC;
false when ?gc_pick_first_virthost_on_nomatch(GC) ->
@@ -968,7 +980,7 @@
pick_host(GC, Host, [SC|T], Group) ->
- case comp_sname(Host, SC#sconf.servername) of
+ case comp_sname(Host, SC#sconf.servername, SC#sconf.serveraliases) of
true -> SC;
false -> pick_host(GC, Host, T, Group)
end;
Index: include/yaws.hrl
===================================================================
RCS file: /cvsroot/erlyaws/yaws/include/yaws.hrl,v
retrieving revision 1.58
diff -u -r1.58 yaws.hrl
--- include/yaws.hrl 18 Oct 2006 13:51:34 -0000 1.58
+++ include/yaws.hrl 6 Nov 2006 11:39:37 -0000
@@ -174,7 +174,8 @@
opaque = [], %% useful in embedded mode
start_mod, %% user provided module to be started
allowed_scripts = [yaws],
- revproxy = []
+ revproxy = [],
+ serveraliases = []
}).
%% we cannot compare sconfs directly due to the ets
--
View this message in context: http://www.nabble.com/virtual-server-with-multiple-names-tf2576005.html#a7197302
Sent from the Yaws mailing list archive at Nabble.com.
|