Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Accept an IPv6 between "[...]" as an fcgi server hostname

Here are some examples:
    php_handler = <fcgi, [::1]:9000>
    fcgi_app_server = [::1]:9000

The square brackets syntax is already used in URLs (http://[::1]:8080/)
and allows to mix an IPv6 address and a port number.

While here, fix a bug in revproxy URL parsing where IPv6 between
brackets were considered as a syntax error.
  • Loading branch information...
commit 2e662ff81fe66a556350807efec713a25e2d00f6 1 parent 52e7b4c
@dumbbell dumbbell authored
Showing with 49 additions and 12 deletions.
  1. +8 −2 doc/yaws.tex
  2. +10 −2 man/yaws.conf.5
  3. +31 −8 src/yaws_config.erl
View
10 doc/yaws.tex
@@ -2648,8 +2648,9 @@ \section{Server Part}
\item \verb+fcgi_app_server = Host:Port+ ---
The hostname and TCP port number of a FastCGI application
- server. The TCP port number is not optional. There is no default
- value.
+ server. To specify an IPv6 address, put it inside square
+ brackets (ex: "[::1]:9000"). The TCP port number is not
+ optional. There is no default value.
\item \verb+fcgi_trace_protocol = true | false+ ---
Enable or disable tracing of FastCGI protocol messages as info log
@@ -3054,6 +3055,11 @@ \section{Server Part}
\begin{verbatim}
php_handler = <fcgi, 127.0.0.1:54321>
\end{verbatim}
+ If you need to specify an IPv6 address, use square
+ brackets:
+\begin{verbatim}
+ php_handler = <fcgi, [::1]:54321>
+\end{verbatim}
The PHP interpreter needs read access to the files it
is to serve. Thus, if you run it in a different
security context than \Yaws\ itself, make sure it has
View
12 man/yaws.conf.5
@@ -500,8 +500,10 @@ Turns on/off statistics gathering for a virtual server. Default is \fIfalse\fR.
.TP
\fBfcgi_app_server = Host:Port\fR
-The hostname and TCP port number of a FastCGI application server. The TCP port
-number is not optional. There is no default value.
+The hostname and TCP port number of a FastCGI application server.
+To specify an IPv6 address, put it inside square brackets (ex:
+"[::1]:9000"). The TCP port number is not optional. There is no default
+value.
.TP
\fBfcgi_trace_protocol = true | false\fR
@@ -915,6 +917,12 @@ make use of this PHP server from Yaws, specify:
php_handler = <fcgi, 127.0.0.1:54321>
.fi
+If you need to specify an IPv6 address, use square brackets:
+
+.nf
+ php_handler = <fcgi, [::1]:54321>
+.fi
+
The PHP interpreter needs read access to the files it is to serve. Thus, if you
run it in a different security context than Yaws itself, make sure it has access
to the .php files.
View
39 src/yaws_config.erl
@@ -639,16 +639,22 @@ yaws_dir() ->
yaws:get_app_dir().
string_to_host_and_port(String) ->
- case string:tokens(String, ":") of
- [Host, Port] ->
+ HostPortRE = "^(?:\\[([^\\]]+)\\]|([^:]+)):([0-9]+)$",
+ REOptions = [{capture, all_but_first, list}],
+ case re:run(String, HostPortRE, REOptions) of
+ {match, [IPv6, HostOrIPv4, Port]} ->
case string:to_integer(Port) of
{Integer, []} when Integer >= 0, Integer =< 65535 ->
- {ok, Host, Integer};
+ case IPv6 of
+ "" -> {ok, HostOrIPv4, Integer};
+ _ -> {ok, IPv6, Integer}
+ end;
_Else ->
{error, ?F("~p is not a valid port number", [Port])}
end;
- _Else ->
- {error, ?F("bad host and port specifier, expected HOST:PORT", [])}
+ nomatch ->
+ {error, ?F("bad host and port specifier, expected HOST:PORT; "
+ "use [IP]:PORT for IPv6 address", [])}
end.
string_to_node_mod_fun(String) ->
@@ -1503,14 +1509,18 @@ fload(FD, server, GC, C, Cs, Lno, Chars) ->
{error, ?F("Expect true|false at line ~w", [Lno])}
end;
- ["fcgi_app_server", '=', Val] ->
- case string_to_host_and_port(Val) of
+ ["fcgi_app_server", '=' | Val] ->
+ HostPortSpec = case Val of
+ [HPS] -> HPS;
+ ['[', HSpec, ']', PSpec] -> "[" ++ HSpec ++ "]" ++ PSpec
+ end,
+ case string_to_host_and_port(HostPortSpec) of
{ok, Host, Port} ->
C2 = C#sconf{fcgi_app_server = {Host, Port}},
fload(FD, server, GC, C2, Cs, Lno+1, Next);
{error, Reason} ->
{error, ?F("Invalid fcgi_app_server ~p at line ~w: ~s",
- [Val, Lno, Reason])}
+ [HostPortSpec, Lno, Reason])}
end;
["fcgi_trace_protocol", '=', Bool] ->
@@ -2405,6 +2415,12 @@ parse_revproxy([Prefix, Url, "intercept_mod", InterceptMod]) ->
Error ->
Error
end;
+parse_revproxy([Prefix, Proto, '[', IPv6, ']', Rest, "intercept_mod", InterceptMod]) ->
+ Url = Proto ++ "[" ++ IPv6 ++ "]" ++ Rest,
+ parse_revproxy([Prefix, Url, "intercept_mod", InterceptMod]);
+parse_revproxy([Prefix, Proto, '[', IPv6, ']', Rest]) ->
+ Url = Proto ++ "[" ++ IPv6 ++ "]" ++ Rest,
+ parse_revproxy([Prefix, Url]);
parse_revproxy(_Other) ->
{error, syntax}.
@@ -2466,6 +2482,13 @@ parse_phpmod(['<', "fcgi", ',', HostPortSpec, '>'], _) ->
{error, Reason} ->
{error, Reason}
end;
+parse_phpmod(['<', "fcgi", ',', '[', HostSpec, ']', PortSpec, '>'], _) ->
+ case string_to_host_and_port("[" ++ HostSpec ++ "]" ++ PortSpec) of
+ {ok, Host, Port} ->
+ {ok, {fcgi, {Host, Port}}};
+ {error, Reason} ->
+ {error, Reason}
+ end;
parse_phpmod(['<', "extern", ',', NodeModFunSpec, '>'], _) ->
case string_to_node_mod_fun(NodeModFunSpec) of
{ok, Node, Mod, Fun} ->
Please sign in to comment.
Something went wrong with that request. Please try again.