blob: 0e04cf8d1ffeed972e78c1db41e9a3c97155c8d1 [file] [log] [blame]
Filip Pytloun6b5bb652015-10-06 16:28:32 +02001
Aleš Komárek296a8442017-04-11 13:22:35 +02002=============
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +03003Usage
Aleš Komárek296a8442017-04-11 13:22:35 +02004=============
Filip Pytloun6b5bb652015-10-06 16:28:32 +02005
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +03006Nginx is an open source reverse proxy server for HTTP, HTTPS,
7SMTP, POP3, and IMAP protocols, as well as a load balancer,
8HTTP cache, and a web server (origin server). The nginx project
9started with a strong focus on high concurrency, high performance
10and low memory usage.
Filip Pytloun6b5bb652015-10-06 16:28:32 +020011
Aleš Komárek296a8442017-04-11 13:22:35 +020012Sample Pillars
Filip Pytloun6b5bb652015-10-06 16:28:32 +020013==============
14
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +030015Gitlab server setup:
Filip Pytloun6b5bb652015-10-06 16:28:32 +020016
17.. code-block:: yaml
18
19 nginx:
20 server:
21 enabled: true
22 bind:
23 address: '0.0.0.0'
24 ports:
25 - 80
26 site:
27 gitlab_domain:
28 enabled: true
29 type: gitlab
30 name: domain
31 ssl:
32 enabled: true
33 key: |
34 -----BEGIN RSA PRIVATE KEY-----
35 ...
36 cert: |
37 xyz
38 chain: |
39 my_chain..
40 host:
41 name: gitlab.domain.com
42 port: 80
43
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +030044Simple static HTTP site:
Filip Pytloun6b5bb652015-10-06 16:28:32 +020045
46.. code-block:: yaml
47
48 nginx:
49 server:
50 site:
51 nginx_static_site01:
52 enabled: true
Niklaus Giger23096b22017-06-30 16:41:49 +020053 type: nginx_static
Filip Pytloun6b5bb652015-10-06 16:28:32 +020054 name: site01
55 host:
56 name: gitlab.domain.com
57 port: 80
58
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +030059Simple load balancer:
Dmitry Stremkovskiy52145c62017-08-21 23:42:17 +030060
61.. code-block:: yaml
62
63 nginx:
64 server:
65 upstream:
66 horizon-upstream:
67 backend1:
68 address: 10.10.10.113
69 port: 8078
70 opts: weight=3
71 backend2:
72 address: 10.10.10.114
73 site:
74 nginx_proxy_openstack_web:
75 enabled: true
76 type: nginx_proxy
77 name: openstack_web
78 proxy:
79 upstream_proxy_pass: http://horizon-upstream
80 host:
81 name: 192.168.0.1
82 port: 31337
83
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +030084Static site with access policy:
Adam Tenglere7746cb2016-04-27 19:01:25 +020085
86.. code-block:: yaml
87
88 nginx:
89 server:
90 site:
91 nginx_static_site01:
92 enabled: true
Niklaus Giger23096b22017-06-30 16:41:49 +020093 type: nginx_static
Adam Tenglere7746cb2016-04-27 19:01:25 +020094 name: site01
95 access_policy:
96 allow:
97 - 192.168.1.1/24
98 - 127.0.0.1
99 deny:
100 - 192.168.1.2
101 - all
102 host:
103 name: gitlab.domain.com
104 port: 80
105
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300106Simple TCP/UDP proxy:
Dmitry Stremkovskiy6484afa2017-08-22 17:07:06 +0300107
108.. code-block:: yaml
109
110 nginx:
111 server:
112 stream:
113 rabbitmq:
114 host:
115 port: 5672
116 backend:
117 server1:
118 address: 10.10.10.113
119 port: 5672
120 least_conn: true
121 hash: "$remote_addr consistent"
122 unbound:
123 host:
124 bind: 127.0.0.1
125 port: 53
126 protocol: udp
127 backend:
128 server1:
129 address: 10.10.10.113
130 port: 5353
131
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300132Simple HTTP proxy:
Filip Pytloun6b5bb652015-10-06 16:28:32 +0200133
134.. code-block:: yaml
135
136 nginx:
137 server:
138 site:
139 nginx_proxy_site01:
140 enabled: true
Niklaus Giger23096b22017-06-30 16:41:49 +0200141 type: nginx_proxy
Filip Pytloun6b5bb652015-10-06 16:28:32 +0200142 name: site01
143 proxy:
144 host: local.domain.com
145 port: 80
146 protocol: http
147 host:
148 name: gitlab.domain.com
149 port: 80
150
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300151Simple HTTP proxy with multiple locations:
152
153.. note:: If proxy part is defined and location is missing ``/``,
154 the proxy part is used. If the ``/`` location is defined,
155 it overrides the proxy part.
Jakub Josef83f7acf2018-04-09 16:05:49 +0200156
157.. code-block:: yaml
158
159 nginx:
160 server:
161 site:
162 nginx_proxy_site01:
163 enabled: true
164 type: nginx_proxy
165 name: site01
166 proxy:
167 host: local.domain.com
168 port: 80
169 protocol: http
170 location:
171 /internal/:
172 host: 172.120.10.200
173 port: 80
174 protocol: http
175 /doc/:
176 host: 172.10.10.200
177 port: 80
178 protocol: http
179 host:
180 name: gitlab.domain.com
181 port: 80
182
183.. code-block:: yaml
184
185 nginx:
186 server:
187 site:
188 nginx_proxy_site01:
189 enabled: true
190 type: nginx_proxy
191 name: site01
192 location:
193 /:
194 host: 172.120.10.200
195 port: 80
196 protocol: http
197 /doc/:
198 host: 172.10.10.200
199 port: 80
200 protocol: http
201 host:
202 name: gitlab.domain.com
203 port: 80
204
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300205Simple Websocket proxy:
Filip Pytloun6b5bb652015-10-06 16:28:32 +0200206
207.. code-block:: yaml
208
209 nginx:
210 server:
211 site:
212 nginx_proxy_site02:
213 enabled: true
Niklaus Giger23096b22017-06-30 16:41:49 +0200214 type: nginx_proxy
Filip Pytloun6b5bb652015-10-06 16:28:32 +0200215 name: site02
216 proxy:
217 websocket: true
218 host: local.domain.com
219 port: 80
220 protocol: http
221 host:
222 name: gitlab.domain.com
223 port: 80
224
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300225Content filtering proxy:
Filip Pytloun6b5bb652015-10-06 16:28:32 +0200226
227.. code-block:: yaml
228
229 nginx:
230 server:
231 enabled: true
232 site:
233 nginx_proxy_site03:
234 enabled: true
Niklaus Giger23096b22017-06-30 16:41:49 +0200235 type: nginx_proxy
Filip Pytloun6b5bb652015-10-06 16:28:32 +0200236 name: site03
237 proxy:
238 host: local.domain.com
239 port: 80
240 protocol: http
241 filter:
242 search: https://www.domain.com
243 replace: http://10.10.10.10
244 host:
245 name: gitlab.domain.com
246 port: 80
247
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300248Proxy with access policy:
Adam Tenglere7746cb2016-04-27 19:01:25 +0200249
250.. code-block:: yaml
251
252 nginx:
253 server:
254 site:
255 nginx_proxy_site01:
256 enabled: true
Niklaus Giger23096b22017-06-30 16:41:49 +0200257 type: nginx_proxy
Adam Tenglere7746cb2016-04-27 19:01:25 +0200258 name: site01
259 access_policy:
260 allow:
261 - 192.168.1.1/24
262 - 127.0.0.1
263 deny:
264 - 192.168.1.2
265 - all
266 proxy:
267 host: local.domain.com
268 port: 80
269 protocol: http
270 host:
271 name: gitlab.domain.com
272 port: 80
273
Vasyl Saienkoc14eca22018-12-07 09:46:17 +0000274Use nginx `ngx_http_map_module` that creates variables whose values depend on
275values of other variables.
Michel Nederlofeb5dd232018-03-13 13:57:34 +0100276
277.. code-block:: yaml
278
Vasyl Saienkoc14eca22018-12-07 09:46:17 +0000279 nginx:
280 server:
281 enabled: true
282 map:
283 enabled: true
284 items:
285 mymap:
286 enabled: true
287 string: input_string
288 variable: output_map_variable
289 body:
290 default:
291 value: '""'
292 example.com:
293 value: '1'
294 example.org:
295 value: '2'
296
297Use nginx `ngx_http_geo_module module` that creates variables with values
298depending on the client IP address.
299
300.. code-block:: yaml
301
302 nginx:
303 server:
304 enabled: true
305 geo:
306 enabled: true
307 items:
308 my_geo_map:
309 enabled: true
310 variable: output_get_variable
311 body:
312 default:
313 value: '""'
314 cl1
315 name: 10.12.100.1/32
316 value: '1'
317 cl2
318 name: 10.13.0.0/16
319 value: 2'
320
321Use `ngx_http_limit_req_module` module that is used to limit the request
322processing rate per a defined key, in particular, the processing rate of
323requests coming from a single IP address. The limitation is done using
324the `leaky bucket` method.
325The `limit_req_module` might be configured globally or applied to specific
326nginx site.
327
328.. code-block:: yaml
329
330 nginx:
331 server:
332 limit_req_module:
333 limit_req_zone:
334 global_limit_ip_zone:
335 key: global_limit_ip_var
336 size: 10m
337 rate: '1r/s'
338 limit_req_status: 503
339 limit_req:
340 global_limit_zone:
341 burst: 5
342 enabled: true
343
344There is an example to to limit requests to all sites based on IP.
345In the following example all clients are limited except of 10.12.100.1
346with 1 req per second.
347
348#. Create geo instance that will match IP and set `limit_action` var.
349 "0" - is unlimited, 1 - limited
350
351#. Create a `global_geo_limiting_map` that will map `ip_limit_key` to
352 `ip_limit_action`
353
354#. Create global `limit_req_zone` called `global_limit_zone` that limits
355 number of requests to 1r/s
356
357#. Apply `global_limit_zone` globally to all requests with 5 req burst.
358
359.. code-block:: yaml
360
361 nginx:
362 server:
363 enabled: true
364 geo:
365 enabled: true
366 items:
367 global_geo_limiting:
368 enabled: true
369 variable: ip_limit_key
370 body:
371 default:
372 value: '1'
373 unlimited_client1:
374 name: '10.12.100.1/32'
375 value: '0'
376 map:
377 enabled: true
378 items:
379 global_geo_limiting_map:
380 enabled: true
381 string: ip_limit_key
382 variable: ip_limit_action
383 body:
384 limited:
385 name: 1
386 value: '$binary_remote_addr'
387 unlimited:
388 name: 0
389 value: '""'
390 limit_req_module:
391 limit_req_zone:
392 global_limit_zone:
393 key: ip_limit_action
394 size: 10m
395 rate: '1r/s'
396 limit_req_status: 503
397 limit_req:
398 global_limit_zone:
399 burst: 5
400 enabled: true
401
402To apply request limiting to particular site only `limit_req` should be
403applied on site level, for example:
404
405.. code-block:: yaml
406
Michel Nederlofeb5dd232018-03-13 13:57:34 +0100407 nginx:
408 server:
409 site:
Vasyl Saienkoc14eca22018-12-07 09:46:17 +0000410 nginx_proxy_openstack_api_keystone:
411 limit_req_module:
412 limit_req:
413 global_limit_zone:
414 burst: 5
415 enabled: true
416
Michel Nederlofeb5dd232018-03-13 13:57:34 +0100417
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300418Gitlab server with user for basic auth:
Filip Pytloun6b5bb652015-10-06 16:28:32 +0200419
420.. code-block:: yaml
421
422 nginx:
423 server:
424 enabled: true
425 user:
426 username1:
427 enabled: true
428 password: magicunicorn
429 htpasswd: htpasswd-site1
430 username2:
431 enabled: true
432 password: magicunicorn
433
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300434Proxy buffering:
Ales Komarekd77b7972015-11-12 11:02:39 +0100435
436.. code-block:: yaml
437
438 nginx:
439 server:
440 enabled: true
441 bind:
442 address: '0.0.0.0'
443 ports:
444 - 80
445 site:
446 gitlab_proxy:
447 enabled: true
Niklaus Giger23096b22017-06-30 16:41:49 +0200448 type: nginx_proxy
Ales Komarekd77b7972015-11-12 11:02:39 +0100449 proxy:
Ondrej Smola5e177bc2017-12-07 12:55:23 +0100450 request_buffer: false
Ales Komarekd77b7972015-11-12 11:02:39 +0100451 buffer:
452 number: 8
453 size: 16
454 host:
455 name: gitlab.domain.com
456 port: 80
457
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300458Let's Encrypt:
Michael Kutý3a5abf12015-12-04 21:03:33 +0100459
460.. code-block:: yaml
461
462 nginx:
463 server:
464 enabled: true
465 bind:
466 address: '0.0.0.0'
467 ports:
468 - 443
469 site:
470 gitlab_domain:
471 enabled: true
472 type: gitlab
473 name: domain
474 ssl:
475 enabled: true
476 engine: letsencrypt
477 host:
478 name: gitlab.domain.com
479 port: 443
480
Filip Pytloune0f75512016-11-03 14:34:26 +0100481SSL using already deployed key and cert file.
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300482
483.. note:: The cert file should already contain CA cert and
484 complete chain.
Filip Pytloune0f75512016-11-03 14:34:26 +0100485
486.. code-block:: yaml
487
488 nginx:
489 server:
490 enabled: true
491 site:
492 mysite:
493 ssl:
494 enabled: true
495 key_file: /etc/ssl/private/mykey.key
496 cert_file: /etc/ssl/cert/mycert.crt
497
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300498Advanced SSL configuration, more information about SSL option
499may be found at http://nginx.org/en/docs/http/ngx_http_ssl_module.html
500
501.. note:: Prior to nginx 1.11.0, only one type of ecdh curve
502 can be applied in ``ssl_ecdh_curve directive``.
503
504 if mode = ``secure`` or mode = ``normal`` and ``ciphers``
505 or ``protocols`` are set, they should have type ``string``.
506 If mode = ``manual``, their type should be ``dict``
507 as shown below.
Vasyl Saienkod3348f62018-02-09 20:08:01 +0200508
509.. code-block:: yaml
510
511 nginx:
512 server:
513 enabled: true
514 site:
515 mysite:
516 ssl:
517 enabled: true
518 mode: 'manual'
519 key_file: /srv/salt/pki/${_param:cluster_name}/${salt:minion:cert:proxy:common_name}.key
520 cert_file: /srv/salt/pki/${_param:cluster_name}/${salt:minion:cert:proxy:common_name}.crt
521 chain_file: /srv/salt/pki/${_param:cluster_name}/${salt:minion:cert:proxy:common_name}-with-chain.crt
522 protocols:
523 TLS1:
524 name: 'TLSv1'
525 enabled: True
526 TLS1_1:
527 name: 'TLSv1.1'
528 enabled: True
529 TLS1_2:
530 name: 'TLSv1.2'
531 enabled: False
532 ciphers:
533 ECDHE_RSA_AES256_GCM_SHA384:
534 name: 'ECDHE-RSA-AES256-GCM-SHA384'
535 enabled: True
536 ECDHE_ECDSA_AES256_GCM_SHA384:
537 name: 'ECDHE-ECDSA-AES256-GCM-SHA384'
538 enabled: True
539 buffer_size: '16k'
540 crl:
541 file: '/etc/ssl/crl.pem'
542 enabled: False
543 dhparam:
544 enabled: True
545 numbits: 2048
546 ecdh_curve:
547 secp384r1:
548 name: 'secp384r1'
549 enabled: False
550 secp521r1:
551 name: 'secp521r1'
552 enabled: True
553 password_file:
554 content: 'testcontent22'
555 enabled: True
556 file: '/etc/ssl/password.key'
557 prefer_server_ciphers: 'on'
558 ticket_key:
559 enabled: True
560 numbytes: 48
561 resolver:
562 address: '127.0.0.1'
563 valid_seconds: '500'
564 timeout_seconds: '60'
565 session_tickets: 'on'
566 stapling: 'off'
567 stapling_file: '/path/to/stapling/file'
568 stapling_responder: 'http://ocsp.example.com/'
569 stapling_verify: 'on'
570 verify_client: 'on'
571 client_certificate:
572 file: '/etc/ssl/client_cert.pem'
573 enabled: False
574 verify_depth: 1
575 session_cache: 'shared:SSL:15m'
576 session_timeout: '15m'
Adam Tengler5c64af62018-06-22 12:17:55 +0000577 strict_transport_security:
578 max_age: 16000000
579 include_subdomains: False
580 always: true
581 enabled: true
Vasyl Saienkod3348f62018-02-09 20:08:01 +0200582
Vasyl Saienkof5c57e22018-09-28 08:54:33 +0000583Setting custom proxy headers:
584
585.. code-block:: yaml
586
587 nginx:
588 server:
589 enabled: true
590 site:
591 custom_headers:
592 type: nginx_proxy
593 proxy_set_header:
594 Host:
595 enabled: true
596 value: "$host:8774"
597 X-Real-IP:
598 enabled: true
599 value: '$remote_addr'
600 X-Forwarded-For:
601 enabled: true
602 value: '$proxy_add_x_forwarded_for'
603 X-Forwarded-Proto:
604 enabled: true
605 value: '$scheme'
606 X-Forwarded-Port:
607 enabled: true
608 value: '$server_port'
609
Dzmitry Stremkouski13772462018-10-27 14:56:47 +0200610Define site catalog indexes:
611
612.. code-block:: yaml
613
614 nginx:
615 server:
616 enabled: true
617 site:
618 nginx_catalog:
619 enabled: true
620 type: nginx_static
621 name: server
622 indexes:
623 - index.htm
624 - index.html
625 host:
626 name: 127.0.0.1
627 port: 80
628
629Define site catalog autoindex:
630
631.. code-block:: yaml
632
633 nginx:
634 server:
635 enabled: true
636 site:
637 nginx_catalog:
638 enabled: true
639 type: nginx_static
640 name: server
641 autoindex: True
642 host:
643 name: 127.0.0.1
644 port: 80
645
646Nginx stats server (required by collectd nginx plugin) (DEPRECATED):
Adam Tenglerc3916572016-01-25 17:46:52 +0100647
Aleš Komárek296a8442017-04-11 13:22:35 +0200648.. code-block:: yaml
Adam Tenglerc3916572016-01-25 17:46:52 +0100649
650 nginx:
651 server:
652 enabled: true
653 site:
654 nginx_stats_server:
655 enabled: true
656 type: nginx_stats
657 name: server
658 host:
659 name: 127.0.0.1
660 port: 8888
661
Dzmitry Stremkouski13772462018-10-27 14:56:47 +0200662or:
663
664.. code-block:: yaml
665
666 nginx:
667 server:
668 enabled: true
669 site:
670 nginx_stats_server:
671 enabled: true
672 root: disabled
673 indexes: []
674 stats: True
675 type: nginx_static
676 name: stat_server
677 host:
678 name: 127.0.0.1
679 address: 127.0.0.1
680 port: 8888
681
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300682Nginx configured to wait for another service/s before
683starting (currently only with systemd):
Adam Tengler86893942018-06-20 14:06:24 +0000684
685.. code-block:: yaml
686
687 nginx:
688 server:
689 wait_for_service:
690 - foo-bar.mount
691 enabled: true
692 site:
693 ...
694
Aleš Komárek296a8442017-04-11 13:22:35 +0200695More Information
696================
Filip Pytloun6b5bb652015-10-06 16:28:32 +0200697
698* http://wiki.nginx.org/Main
699* https://wiki.mozilla.org/Security/Server_Side_TLS#Modern_compatibility
700* http://nginx.com/resources/admin-guide/reverse-proxy/
701* https://mozilla.github.io/server-side-tls/ssl-config-generator/
Filip Pytloun2e902c12017-02-02 13:02:03 +0100702
703Documentation and Bugs
704======================
705
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300706* http://salt-formulas.readthedocs.io/
707 Learn how to install and update salt-formulas
Filip Pytloun2e902c12017-02-02 13:02:03 +0100708
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300709* https://github.com/salt-formulas/salt-formula-nginx/issues
710 In the unfortunate event that bugs are discovered, report the issue to the
711 appropriate issue tracker. Use the Github issue tracker for a specific salt
712 formula
Filip Pytloun2e902c12017-02-02 13:02:03 +0100713
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300714* https://launchpad.net/salt-formulas
715 For feature requests, bug reports, or blueprints affecting the entire
716 ecosystem, use the Launchpad salt-formulas project
Filip Pytloun2e902c12017-02-02 13:02:03 +0100717
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300718* https://launchpad.net/~salt-formulas-users
719 Join the salt-formulas-users team and subscribe to mailing list if required
Filip Pytloun2e902c12017-02-02 13:02:03 +0100720
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300721* https://github.com/salt-formulas/salt-formula-nginx
722 Develop the salt-formulas projects in the master branch and then submit pull
723 requests against a specific formula
Filip Pytloun2e902c12017-02-02 13:02:03 +0100724
OlgaGusarenkoe2f808f2018-07-30 23:42:18 +0300725* #salt-formulas @ irc.freenode.net
726 Use this IRC channel in case of any questions or feedback which is always
727 welcome