| 1 |
<?xml version="1.0"?> |
| 2 |
<!--*-nxml-*--> |
| 3 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 4 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 5 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 6 |
<refentry id="systemd-socket-proxyd" |
| 7 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 8 |
|
| 9 |
<refentryinfo> |
| 10 |
<title>systemd-socket-proxyd</title> |
| 11 |
<productname>systemd</productname> |
| 12 |
</refentryinfo> |
| 13 |
<refmeta> |
| 14 |
<refentrytitle>systemd-socket-proxyd</refentrytitle> |
| 15 |
<manvolnum>8</manvolnum> |
| 16 |
</refmeta> |
| 17 |
<refnamediv> |
| 18 |
<refname>systemd-socket-proxyd</refname> |
| 19 |
<refpurpose>Bidirectionally proxy local sockets to another (possibly remote) socket</refpurpose> |
| 20 |
</refnamediv> |
| 21 |
<refsynopsisdiv> |
| 22 |
<cmdsynopsis> |
| 23 |
<command>systemd-socket-proxyd</command> |
| 24 |
<arg choice="opt" rep="repeat"><replaceable>OPTIONS</replaceable></arg> |
| 25 |
<arg choice="plain"><replaceable>HOST</replaceable>:<replaceable>PORT</replaceable></arg> |
| 26 |
</cmdsynopsis> |
| 27 |
<cmdsynopsis> |
| 28 |
<command>systemd-socket-proxyd</command> |
| 29 |
<arg choice="opt" rep="repeat"><replaceable>OPTIONS</replaceable></arg> |
| 30 |
<arg choice="plain"><replaceable>UNIX-DOMAIN-SOCKET-PATH</replaceable> |
| 31 |
</arg> |
| 32 |
</cmdsynopsis> |
| 33 |
</refsynopsisdiv> |
| 34 |
<refsect1> |
| 35 |
<title>Description</title> |
| 36 |
<para> |
| 37 |
<command>systemd-socket-proxyd</command> is a generic |
| 38 |
socket-activated network socket forwarder proxy daemon for IPv4, |
| 39 |
IPv6 and UNIX stream sockets. It may be used to bi-directionally |
| 40 |
forward traffic from a local listening socket to a local or remote |
| 41 |
destination socket.</para> |
| 42 |
|
| 43 |
<para>One use of this tool is to provide socket activation support |
| 44 |
for services that do not natively support socket activation. On |
| 45 |
behalf of the service to activate, the proxy inherits the socket |
| 46 |
from systemd, accepts each client connection, opens a connection |
| 47 |
to a configured server for each client, and then bidirectionally |
| 48 |
forwards data between the two.</para> |
| 49 |
<para>This utility's behavior is similar to |
| 50 |
<citerefentry project='die-net'><refentrytitle>socat</refentrytitle><manvolnum>1</manvolnum></citerefentry>. |
| 51 |
The main differences for <command>systemd-socket-proxyd</command> |
| 52 |
are support for socket activation with |
| 53 |
<literal>Accept=no</literal> and an event-driven |
| 54 |
design that scales better with the number of |
| 55 |
connections.</para> |
| 56 |
|
| 57 |
<para>Note that <command>systemd-socket-proxyd</command> will not forward socket side channel |
| 58 |
information, i.e. will not forward <constant>SCM_RIGHTS</constant>, <constant>SCM_CREDENTIALS</constant>, |
| 59 |
<constant>SCM_SECURITY</constant>, <constant>SO_PEERCRED</constant>, <constant>SO_PEERPIDFD</constant>, |
| 60 |
<constant>SO_PEERSEC</constant>, <constant>SO_PEERGROUPS</constant> and similar.</para> |
| 61 |
</refsect1> |
| 62 |
<refsect1> |
| 63 |
<title>Options</title> |
| 64 |
<para>The following options are understood:</para> |
| 65 |
<variablelist> |
| 66 |
<xi:include href="standard-options.xml" xpointer="help" /> |
| 67 |
<xi:include href="standard-options.xml" xpointer="version" /> |
| 68 |
<varlistentry> |
| 69 |
<term><option>--connections-max=</option></term> |
| 70 |
<term><option>-c</option></term> |
| 71 |
|
| 72 |
<listitem><para>Sets the maximum number of simultaneous connections, defaults to 256. |
| 73 |
If the limit of concurrent connections is reached further connections will be refused.</para> |
| 74 |
|
| 75 |
<xi:include href="version-info.xml" xpointer="v233"/></listitem> |
| 76 |
</varlistentry> |
| 77 |
<varlistentry> |
| 78 |
<term><option>--exit-idle-time=</option></term> |
| 79 |
|
| 80 |
<listitem><para>Sets the time before exiting when there are no connections, defaults to |
| 81 |
<constant>infinity</constant>. Takes a unit-less value in seconds, or a time span value such |
| 82 |
as <literal>5min 20s</literal>.</para> |
| 83 |
|
| 84 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 85 |
</varlistentry> |
| 86 |
<varlistentry> |
| 87 |
<term><option>--proxy-protocol=</option></term> |
| 88 |
|
| 89 |
<listitem><para>Uses the <ulink url="https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt">PROXY protocol</ulink> |
| 90 |
to communicate with the server. This allows an appropriately configured server to know the real client IP address. |
| 91 |
Takes the version of the <ulink url="https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt">PROXY protocol</ulink> |
| 92 |
used, and only supports <literal>v1</literal> for now. |
| 93 |
Default is not to use a PROXY protocol.</para> |
| 94 |
|
| 95 |
<xi:include href="version-info.xml" xpointer="v261"/></listitem> |
| 96 |
</varlistentry> |
| 97 |
</variablelist> |
| 98 |
</refsect1> |
| 99 |
<refsect1> |
| 100 |
<title>Exit status</title> |
| 101 |
<para>On success, 0 is returned, a non-zero failure |
| 102 |
code otherwise.</para> |
| 103 |
</refsect1> |
| 104 |
<refsect1> |
| 105 |
<title>Examples</title> |
| 106 |
<refsect2> |
| 107 |
<title>Simple Example</title> |
| 108 |
<para>Use two services with a dependency and no namespace |
| 109 |
isolation.</para> |
| 110 |
<example> |
| 111 |
<title>proxy-to-nginx.socket</title> |
| 112 |
<programlisting><![CDATA[[Socket] |
| 113 |
ListenStream=80 |
| 114 |
|
| 115 |
[Install] |
| 116 |
WantedBy=sockets.target]]></programlisting> |
| 117 |
</example> |
| 118 |
<example> |
| 119 |
<title>proxy-to-nginx.service</title> |
| 120 |
<programlisting><![CDATA[[Unit] |
| 121 |
Requires=nginx.service |
| 122 |
After=nginx.service |
| 123 |
Requires=proxy-to-nginx.socket |
| 124 |
After=proxy-to-nginx.socket |
| 125 |
|
| 126 |
[Service] |
| 127 |
Type=notify |
| 128 |
ExecStart=/usr/lib/systemd/systemd-socket-proxyd /run/nginx/socket |
| 129 |
PrivateTmp=yes |
| 130 |
PrivateNetwork=yes]]></programlisting> |
| 131 |
</example> |
| 132 |
<example> |
| 133 |
<title>nginx.conf</title> |
| 134 |
<programlisting> |
| 135 |
<![CDATA[[…] |
| 136 |
server { |
| 137 |
listen unix:/run/nginx/socket; |
| 138 |
[…]]]> |
| 139 |
</programlisting> |
| 140 |
</example> |
| 141 |
<example> |
| 142 |
<title>Enabling the proxy</title> |
| 143 |
<programlisting><![CDATA[# systemctl enable --now proxy-to-nginx.socket |
| 144 |
$ curl http://localhost:80/]]></programlisting> |
| 145 |
</example> |
| 146 |
<para>If <filename>nginx.service</filename> has <varname>StopWhenUnneeded=</varname> set, then |
| 147 |
passing <option>--exit-idle-time=</option> to <command>systemd-socket-proxyd</command> allows |
| 148 |
both services to stop during idle periods.</para> |
| 149 |
</refsect2> |
| 150 |
<refsect2> |
| 151 |
<title>Namespace Example</title> |
| 152 |
<para>Similar as above, but runs the socket proxy and the main |
| 153 |
service in the same private namespace, assuming that |
| 154 |
<filename>nginx.service</filename> has |
| 155 |
<varname>PrivateTmp=</varname> and |
| 156 |
<varname>PrivateNetwork=</varname> set, too.</para> |
| 157 |
<example> |
| 158 |
<title>proxy-to-nginx.socket</title> |
| 159 |
<programlisting><![CDATA[[Socket] |
| 160 |
ListenStream=80 |
| 161 |
|
| 162 |
[Install] |
| 163 |
WantedBy=sockets.target]]></programlisting> |
| 164 |
</example> |
| 165 |
<example> |
| 166 |
<title>proxy-to-nginx.service</title> |
| 167 |
<programlisting><![CDATA[[Unit] |
| 168 |
Requires=nginx.service |
| 169 |
After=nginx.service |
| 170 |
Requires=proxy-to-nginx.socket |
| 171 |
After=proxy-to-nginx.socket |
| 172 |
JoinsNamespaceOf=nginx.service |
| 173 |
|
| 174 |
[Service] |
| 175 |
Type=notify |
| 176 |
ExecStart=/usr/lib/systemd/systemd-socket-proxyd 127.0.0.1:8080 |
| 177 |
PrivateTmp=yes |
| 178 |
PrivateNetwork=yes]]></programlisting> |
| 179 |
</example> |
| 180 |
<example> |
| 181 |
<title>nginx.conf</title> |
| 182 |
<programlisting><![CDATA[[…] |
| 183 |
server { |
| 184 |
listen 8080; |
| 185 |
[…]]]></programlisting> |
| 186 |
</example> |
| 187 |
<example> |
| 188 |
<title>Enabling the proxy</title> |
| 189 |
<programlisting><![CDATA[# systemctl enable --now proxy-to-nginx.socket |
| 190 |
$ curl http://localhost:80/]]></programlisting> |
| 191 |
</example> |
| 192 |
</refsect2> |
| 193 |
<refsect2> |
| 194 |
<title>PROXY protocol example with nginx</title> |
| 195 |
<para>systemd-socket-proxyd and nginx using the PROXY protocol</para> |
| 196 |
<example> |
| 197 |
<title>proxy-to-nginx.socket</title> |
| 198 |
<programlisting><![CDATA[[Socket] |
| 199 |
ListenStream=80 |
| 200 |
|
| 201 |
[Install] |
| 202 |
WantedBy=sockets.target]]></programlisting> |
| 203 |
</example> |
| 204 |
<example> |
| 205 |
<title>proxy-to-nginx.service</title> |
| 206 |
<programlisting><![CDATA[[Unit] |
| 207 |
Requires=nginx.service |
| 208 |
After=nginx.service |
| 209 |
Requires=proxy-to-nginx.socket |
| 210 |
After=proxy-to-nginx.socket |
| 211 |
|
| 212 |
[Service] |
| 213 |
Type=notify |
| 214 |
ExecStart=/usr/lib/systemd/systemd-socket-proxyd --proxy-protocol=v1 /run/nginx/socket |
| 215 |
PrivateTmp=yes |
| 216 |
PrivateNetwork=yes]]></programlisting> |
| 217 |
</example> |
| 218 |
<example> |
| 219 |
<title>nginx.conf</title> |
| 220 |
<programlisting> |
| 221 |
<![CDATA[[…] |
| 222 |
server { |
| 223 |
listen unix:/run/nginx/socket proxy_protocol; |
| 224 |
real_ip_header proxy_protocol; |
| 225 |
[…]]]> |
| 226 |
</programlisting> |
| 227 |
</example> |
| 228 |
<example> |
| 229 |
<title>Enabling the proxy</title> |
| 230 |
<programlisting><![CDATA[# systemctl enable --now proxy-to-nginx.socket |
| 231 |
$ curl http://localhost:80/]]></programlisting> |
| 232 |
</example> |
| 233 |
</refsect2> |
| 234 |
</refsect1> |
| 235 |
<refsect1> |
| 236 |
<title>See Also</title> |
| 237 |
<para><simplelist type="inline"> |
| 238 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 239 |
<member><citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 240 |
<member><citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 241 |
<member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 242 |
<member><citerefentry project='die-net'><refentrytitle>socat</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 243 |
<member><citerefentry project='die-net'><refentrytitle>nginx</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 244 |
<member><citerefentry project='die-net'><refentrytitle>curl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 245 |
<member><ulink url="https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt">PROXY protocol specification</ulink></member> |
| 246 |
<member><ulink url="https://docs.nginx.com/nginx/admin-guide/load-balancer/using-proxy-protocol/">nginx: Accepting the PROXY Protocol</ulink></member> |
| 247 |
</simplelist></para> |
| 248 |
</refsect1> |
| 249 |
</refentry> |