stdiscosrv.1 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. .\" Man page generated from reStructuredText.
  2. .
  3. .
  4. .nr rst2man-indent-level 0
  5. .
  6. .de1 rstReportMargin
  7. \\$1 \\n[an-margin]
  8. level \\n[rst2man-indent-level]
  9. level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
  10. -
  11. \\n[rst2man-indent0]
  12. \\n[rst2man-indent1]
  13. \\n[rst2man-indent2]
  14. ..
  15. .de1 INDENT
  16. .\" .rstReportMargin pre:
  17. . RS \\$1
  18. . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
  19. . nr rst2man-indent-level +1
  20. .\" .rstReportMargin post:
  21. ..
  22. .de UNINDENT
  23. . RE
  24. .\" indent \\n[an-margin]
  25. .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
  26. .nr rst2man-indent-level -1
  27. .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
  28. .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
  29. ..
  30. .TH "STDISCOSRV" "1" "Sep 13, 2024" "v1.27.11" "Syncthing"
  31. .SH NAME
  32. stdiscosrv \- Syncthing Discovery Server
  33. .SH SYNOPSIS
  34. .INDENT 0.0
  35. .INDENT 3.5
  36. .sp
  37. .EX
  38. stdiscosrv [\-\-debug] [\-\-http] [\-\-compression] [\-\-version]
  39. [\-\-cert=<file>] [\-\-key=<string>]
  40. [\-\-listen=<address>] [\-\-metrics\-listen=<address>]
  41. [\-\-db\-dir=<string>] [\-\-db\-flush\-interval=<string>]
  42. .EE
  43. .UNINDENT
  44. .UNINDENT
  45. .SH DESCRIPTION
  46. .sp
  47. Syncthing relies on a discovery server to find peers on the internet. Anyone
  48. can run a discovery server and point Syncthing installations to it. The
  49. Syncthing project also maintains a global cluster for public use.
  50. .SH OPTIONS
  51. .INDENT 0.0
  52. .TP
  53. .B \-\-debug
  54. Enable debug output.
  55. .UNINDENT
  56. .INDENT 0.0
  57. .TP
  58. .B \-\-http
  59. Listen on HTTP (behind an HTTPS proxy).
  60. .UNINDENT
  61. .INDENT 0.0
  62. .TP
  63. .B \-\-version
  64. Print the current version number and exit.
  65. .UNINDENT
  66. .INDENT 0.0
  67. .TP
  68. .B \-\-compression
  69. Enable GZIP compression of HTTP responses.
  70. .UNINDENT
  71. .INDENT 0.0
  72. .TP
  73. .B \-\-cert=<file>
  74. Certificate file (default “./cert.pem”). Unused in –http mode.
  75. .UNINDENT
  76. .INDENT 0.0
  77. .TP
  78. .B \-\-key=<file>
  79. Key file (default “./key.pem”). Unused in –http mode.
  80. .UNINDENT
  81. .INDENT 0.0
  82. .TP
  83. .B \-\-listen=<address>
  84. Listen address (default “:8443”).
  85. .UNINDENT
  86. .INDENT 0.0
  87. .TP
  88. .B \-\-metrics\-listen=<address>
  89. Prometheus compatible metrics endpoint listen address (default
  90. disabled).
  91. .UNINDENT
  92. .INDENT 0.0
  93. .TP
  94. .B \-\-db\-dir=<string>
  95. Database directory, where data is stored (default “.”).
  96. .UNINDENT
  97. .INDENT 0.0
  98. .TP
  99. .B \-\-db\-flush\-interval=<string>
  100. Interval at which the in\-memory database is flushed to disk (default
  101. “5m”).
  102. .UNINDENT
  103. .SH POINTING SYNCTHING AT YOUR DISCOVERY SERVER
  104. .sp
  105. By default, Syncthing uses a number of global discovery servers, signified by
  106. the entry \fBdefault\fP in the list of discovery servers. To make Syncthing use
  107. your own instance of stdiscosrv, open up Syncthing’s web GUI. Go to settings,
  108. Global Discovery Server and add stdiscosrv’s host address to the comma\-separated
  109. list, e.g. \fBhttps://disco.example.com:8443/\fP\&. Note that stdiscosrv uses port
  110. 8443 by default. For stdiscosrv to be available over the internet with a dynamic
  111. IP address, you will need a dynamic DNS service.
  112. .sp
  113. Deprecated since version v0.14.44: Prior versions need \fB/v2/\fP appended to the discovery
  114. server address, e.g. \fBhttps://disco.example.com:8443/v2/\fP\&.
  115. .sp
  116. If you wish to use \fIonly\fP your own discovery server, remove the \fBdefault\fP
  117. entry from the list.
  118. .SH SETTING UP
  119. .SS Description
  120. .sp
  121. This guide assumes that you have already set up Syncthing. If you
  122. haven’t yet, head over to \fI\%Getting Started\fP first.
  123. .SS Installing
  124. .sp
  125. Go to \X'tty: link https://github.com/syncthing/discosrv/releases'\fI\%releases\fP <\fBhttps://github.com/syncthing/discosrv/releases\fP>\X'tty: link' and
  126. download the file appropriate for your operating system. Unpacking it will
  127. yield a binary called \fBstdiscosrv\fP (or \fBstdiscosrv.exe\fP on Windows).
  128. Start this in whatever way you are most comfortable with; double clicking
  129. should work in any graphical environment. At first start, stdiscosrv will
  130. generate certificate files and database in the current directory unless
  131. given flags to the contrary.
  132. .sp
  133. The discovery server can also be obtained through apt, the Debian/Ubuntu package
  134. manager. Recent releases can be found at syncthing’s
  135. \X'tty: link https://apt.syncthing.net/'\fI\%apt repository\fP <\fBhttps://apt.syncthing.net/\fP>\X'tty: link'\&. The name of the package is
  136. syncthing\-discosrv.
  137. .SS Configuring
  138. .sp
  139. \fBNOTE:\fP
  140. .INDENT 0.0
  141. .INDENT 3.5
  142. If you are running an instance of Syncthing on the discovery server,
  143. you must either add that instance to other devices using a static
  144. address or bind the discovery server and Syncthing instances to
  145. different IP addresses.
  146. .UNINDENT
  147. .UNINDENT
  148. .SS Certificates
  149. .sp
  150. The discovery server provides service over HTTPS. To ensure secure connections
  151. from clients there are three options:
  152. .INDENT 0.0
  153. .IP \(bu 2
  154. Use a CA\-signed certificate pair for the domain name you will use for the
  155. discovery server. This is like any other HTTPS website; clients will
  156. authenticate the server based on its certificate and domain name.
  157. .IP \(bu 2
  158. Use any certificate pair and let clients authenticate the server based on
  159. its “device ID” (similar to Syncthing\-to\-Syncthing authentication). This
  160. option can be used with the certificate automatically generated by the
  161. discovery server.
  162. .IP \(bu 2
  163. Pass the \fB\-\-http\fP flag if the discovery server is behind an SSL\-secured
  164. reverse proxy. See below for configuration.
  165. .UNINDENT
  166. .sp
  167. For the first two options, the discovery server must be given the paths to
  168. the certificate and key at startup. This isn’t necessary with the \fBhttp\fP flag:
  169. .INDENT 0.0
  170. .INDENT 3.5
  171. .sp
  172. .EX
  173. $ stdiscosrv \-\-cert=/path/to/cert.pem \-\-key=/path/to/key.pem
  174. Server device ID is 7DDRT7J\-UICR4PM\-PBIZYL3\-MZOJ7X7\-EX56JP6\-IK6HHMW\-S7EK32W\-G3EUPQA
  175. .EE
  176. .UNINDENT
  177. .UNINDENT
  178. .sp
  179. The discovery server prints its device ID at startup. In case you are using
  180. a non CA signed certificate, this device ID (fingerprint) must be given to
  181. the clients in the discovery server URL:
  182. .INDENT 0.0
  183. .INDENT 3.5
  184. .sp
  185. .EX
  186. https://disco.example.com:8443/?id=7DDRT7J\-UICR4PM\-PBIZYL3\-MZOJ7X7\-EX56JP6\-IK6HHMW\-S7EK32W\-G3EUPQA
  187. .EE
  188. .UNINDENT
  189. .UNINDENT
  190. .sp
  191. Otherwise, the URL will be:
  192. .INDENT 0.0
  193. .INDENT 3.5
  194. .sp
  195. .EX
  196. https://disco.example.com:8443/
  197. .EE
  198. .UNINDENT
  199. .UNINDENT
  200. .SS Reverse Proxy Setup
  201. .sp
  202. Added in version 1.8.0: A new “X\-Client\-Port” HTTP header was added.
  203. .sp
  204. The discovery server can be run behind an SSL\-secured reverse proxy. This
  205. allows:
  206. .INDENT 0.0
  207. .IP \(bu 2
  208. Use of a subdomain name without requiring a port number added to the URL
  209. .IP \(bu 2
  210. Sharing an SSL certificate with multiple services on the same server
  211. .UNINDENT
  212. .sp
  213. Note that after this configuration, if the proxy uses a valid HTTPS
  214. certificate, \fBclients should omit the\fP \fB?id=...\fP \fBparameter from the
  215. discovery server URL on their configuration\fP\&. Client\-side validation will be
  216. done by checking the visible proxy server’s HTTPS certificate. If, however, the
  217. proxy uses a self\-signed or somehow invalid certificate, clients must still set
  218. the \fB?id=...\fP parameter with the computed hash of the proxy’s
  219. certificate. Using such setup is discouraged and is not covered in this page.
  220. Always favour using valid and widely recognised certificates.
  221. .SS Requirements
  222. .INDENT 0.0
  223. .IP \(bu 2
  224. Run the discovery server using the \-http flag: \fBstdiscosrv \-http\fP\&.
  225. .IP \(bu 2
  226. SSL certificate/key configured for the reverse proxy.
  227. .IP \(bu 2
  228. The “X\-Forwarded\-For” HTTP header must be passed through with the client’s
  229. real IP address.
  230. .IP \(bu 2
  231. The “X\-Client\-Port” HTTP header should be passed through, containing the client’s real connection port.
  232. .IP \(bu 2
  233. The “X\-SSL\-Cert” HTTP header must be passed through with the PEM\-encoded
  234. client SSL certificate. This will be present in POST requests and may be empty
  235. in GET requests from clients. If you see syncthing\-discosrv outputting
  236. \fBno certificates\fP when receiving POST requests, that’s because the proxy
  237. is not passing this header through.
  238. .IP \(bu 2
  239. The proxy must request the client SSL certificate but not require it to be
  240. signed by a trusted CA.
  241. .UNINDENT
  242. .SS Nginx
  243. .sp
  244. These lines in the configuration take care of the last four requirements
  245. listed above:
  246. .INDENT 0.0
  247. .INDENT 3.5
  248. .sp
  249. .EX
  250. proxy_set_header X\-Forwarded\-For $proxy_add_x_forwarded_for;
  251. proxy_set_header X\-Client\-Port $remote_port;
  252. proxy_set_header X\-SSL\-Cert $ssl_client_cert;
  253. ssl_verify_client optional_no_ca;
  254. .EE
  255. .UNINDENT
  256. .UNINDENT
  257. .sp
  258. The following is a complete example Nginx configuration file. With this setup,
  259. clients can use \X'tty: link https://discovery.example.com'\fI\%https://discovery.example.com\fP\X'tty: link' as the discovery server URL in
  260. the Syncthing settings.
  261. .INDENT 0.0
  262. .INDENT 3.5
  263. .sp
  264. .EX
  265. # HTTP 1.1 support
  266. proxy_http_version 1.1;
  267. proxy_buffering off;
  268. proxy_set_header Host $http_host;
  269. proxy_set_header Upgrade $http_upgrade;
  270. proxy_set_header Connection $http_connection;
  271. proxy_set_header X\-Real\-IP $remote_addr;
  272. proxy_set_header X\-Client\-Port $remote_port;
  273. proxy_set_header X\-Forwarded\-For $proxy_add_x_forwarded_for;
  274. proxy_set_header X\-Forwarded\-Proto $http_x_forwarded_proto;
  275. proxy_set_header X\-SSL\-Cert $ssl_client_cert;
  276. upstream discovery.example.com {
  277. # Local IP address:port for discovery server
  278. server 192.0.2.1:8443;
  279. }
  280. server {
  281. server_name discovery.example.com;
  282. listen 80;
  283. access_log /var/log/nginx/access.log vhost;
  284. return 301 https://$host$request_uri;
  285. }
  286. server {
  287. server_name discovery.example.com;
  288. listen 443 ssl http2;
  289. access_log /var/log/nginx/access.log vhost;
  290. # Mozilla Intermediate configuration (https://wiki.mozilla.org/Security/Server_Side_TLS)
  291. ssl_protocols TLSv1.2 TLSv1.3;
  292. ssl_ciphers ECDHE\-ECDSA\-AES128\-GCM\-SHA256:ECDHE\-RSA\-AES128\-GCM\-SHA256:ECDHE\-ECDSA\-AES256\-GCM\-SHA384:ECDHE\-RSA\-AES256\-GCM\-SHA384:ECDHE\-ECDSA\-CHACHA20\-POLY1305:ECDHE\-RSA\-CHACHA20\-POLY1305:DHE\-RSA\-AES128\-GCM\-SHA256:DHE\-RSA\-AES256\-GCM\-SHA384;
  293. ssl_prefer_server_ciphers off;
  294. ssl_session_tickets off;
  295. ssl_session_timeout 5m;
  296. ssl_session_cache shared:SSL:50m;
  297. ssl_verify_client optional_no_ca;
  298. # OCSP stapling
  299. ssl_stapling on;
  300. ssl_stapling_verify on;
  301. # Certificates
  302. ssl_certificate /etc/nginx/certs/discovery.example.com.crt;
  303. ssl_certificate_key /etc/nginx/certs/discovery.example.com.key;
  304. # curl https://ssl\-config.mozilla.org/ffdhe2048.txt > /path/to/dhparam
  305. ssl_dhparam /path/to/dhparam;
  306. # HSTS (ngx_http_headers_module is required) (63072000 seconds)
  307. add_header Strict\-Transport\-Security \(dqmax\-age=63072000\(dq always;
  308. location / {
  309. proxy_pass http://discovery.example.com;
  310. }
  311. }
  312. .EE
  313. .UNINDENT
  314. .UNINDENT
  315. .sp
  316. An example of automating the SSL certificates and reverse\-proxying the Discovery
  317. Server and Syncthing using Nginx, \X'tty: link https://letsencrypt.org/'\fI\%Let’s Encrypt\fP <\fBhttps://letsencrypt.org/\fP>\X'tty: link' and Docker can be found \X'tty: link https://forum.syncthing.net/t/docker-syncthing-and-syncthing-discovery-behind-nginx-reverse-proxy-with-lets-encrypt/6880'\fI\%here\fP <\fBhttps://forum.syncthing.net/t/docker-syncthing-and-syncthing-discovery-behind-nginx-reverse-proxy-with-lets-encrypt/6880\fP>\X'tty: link'\&.
  318. .SS Apache
  319. .sp
  320. The following lines must be added to the configuration:
  321. .INDENT 0.0
  322. .INDENT 3.5
  323. .sp
  324. .EX
  325. SSLProxyEngine On
  326. SSLVerifyClient optional_no_ca
  327. RequestHeader set X\-SSL\-Cert \(dq%{SSL_CLIENT_CERT}s\(dq
  328. .EE
  329. .UNINDENT
  330. .UNINDENT
  331. .sp
  332. The following was observed to not be required at least under
  333. Apache httpd 2.4.38, as the proxy module adds the needed header by default.
  334. If you need to explicitly add the following directive, make sure to issue
  335. \fBa2enmod remoteip\fP first. Then, add the following to your Apache httpd
  336. configuration:
  337. .INDENT 0.0
  338. .INDENT 3.5
  339. .sp
  340. .EX
  341. RemoteIPHeader X\-Forwarded\-For
  342. .EE
  343. .UNINDENT
  344. .UNINDENT
  345. .SS Caddy
  346. .sp
  347. The following lines must be added to the Caddyfile:
  348. .INDENT 0.0
  349. .INDENT 3.5
  350. .sp
  351. .EX
  352. discovery.example.com {
  353. reverse_proxy 192.0.2.1:8443 {
  354. header_up X\-Forwarded\-For {http.request.remote.host}
  355. header_up X\-Client\-Port {http.request.remote.port}
  356. header_up X\-Tls\-Client\-Cert\-Der\-Base64 {http.request.tls.client.certificate_der_base64}
  357. }
  358. tls {
  359. client_auth {
  360. mode request
  361. }
  362. }
  363. }
  364. .EE
  365. .UNINDENT
  366. .UNINDENT
  367. .INDENT 0.0
  368. .INDENT 3.5
  369. .sp
  370. .EX
  371. .EE
  372. .UNINDENT
  373. .UNINDENT
  374. .sp
  375. For more details, see also the recommendations in the
  376. \X'tty: link https://docs.syncthing.net/users/reverseproxy.html'\fI\%Reverse Proxy Setup\fP <\fBhttps://docs.syncthing.net/users/reverseproxy.html\fP>\X'tty: link'
  377. page. Note that that page is directed at setting up a proxy for the
  378. Syncthing web UI. You should do the proper path and port adjustments to proxying
  379. the discovery server and your particular setup.
  380. .SH SEE ALSO
  381. .sp
  382. \fBsyncthing\-networking(7)\fP, \fBsyncthing\-faq(7)\fP
  383. .SH AUTHOR
  384. The Syncthing Authors
  385. .SH COPYRIGHT
  386. 2014-2019, The Syncthing Authors
  387. .\" Generated by docutils manpage writer.
  388. .