| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 1 |  | 
| Aleš Komárek | 296a844 | 2017-04-11 13:22:35 +0200 | [diff] [blame] | 2 | ============= | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 3 | Usage | 
| Aleš Komárek | 296a844 | 2017-04-11 13:22:35 +0200 | [diff] [blame] | 4 | ============= | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 5 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 6 | Nginx is an open source reverse proxy server for HTTP, HTTPS, | 
|  | 7 | SMTP, POP3, and IMAP protocols, as well as a load balancer, | 
|  | 8 | HTTP cache, and a web server (origin server). The nginx project | 
|  | 9 | started with a strong focus on high concurrency, high performance | 
|  | 10 | and low memory usage. | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 11 |  | 
| Aleš Komárek | 296a844 | 2017-04-11 13:22:35 +0200 | [diff] [blame] | 12 | Sample Pillars | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 13 | ============== | 
|  | 14 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 15 | Gitlab server setup: | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 16 |  | 
|  | 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 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 44 | Simple static HTTP site: | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 45 |  | 
|  | 46 | .. code-block:: yaml | 
|  | 47 |  | 
|  | 48 | nginx: | 
|  | 49 | server: | 
|  | 50 | site: | 
|  | 51 | nginx_static_site01: | 
|  | 52 | enabled: true | 
| Niklaus Giger | 23096b2 | 2017-06-30 16:41:49 +0200 | [diff] [blame] | 53 | type: nginx_static | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 54 | name: site01 | 
|  | 55 | host: | 
|  | 56 | name: gitlab.domain.com | 
|  | 57 | port: 80 | 
|  | 58 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 59 | Simple load balancer: | 
| Dmitry Stremkovskiy | 52145c6 | 2017-08-21 23:42:17 +0300 | [diff] [blame] | 60 |  | 
|  | 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 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 84 | Static site with access policy: | 
| Adam Tengler | e7746cb | 2016-04-27 19:01:25 +0200 | [diff] [blame] | 85 |  | 
|  | 86 | .. code-block:: yaml | 
|  | 87 |  | 
|  | 88 | nginx: | 
|  | 89 | server: | 
|  | 90 | site: | 
|  | 91 | nginx_static_site01: | 
|  | 92 | enabled: true | 
| Niklaus Giger | 23096b2 | 2017-06-30 16:41:49 +0200 | [diff] [blame] | 93 | type: nginx_static | 
| Adam Tengler | e7746cb | 2016-04-27 19:01:25 +0200 | [diff] [blame] | 94 | 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 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 106 | Simple TCP/UDP proxy: | 
| Dmitry Stremkovskiy | 6484afa | 2017-08-22 17:07:06 +0300 | [diff] [blame] | 107 |  | 
|  | 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 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 132 | Simple HTTP proxy: | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 133 |  | 
|  | 134 | .. code-block:: yaml | 
|  | 135 |  | 
|  | 136 | nginx: | 
|  | 137 | server: | 
|  | 138 | site: | 
|  | 139 | nginx_proxy_site01: | 
|  | 140 | enabled: true | 
| Niklaus Giger | 23096b2 | 2017-06-30 16:41:49 +0200 | [diff] [blame] | 141 | type: nginx_proxy | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 142 | 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 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 151 | Simple 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 Josef | 83f7acf | 2018-04-09 16:05:49 +0200 | [diff] [blame] | 156 |  | 
|  | 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 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 205 | Simple Websocket proxy: | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 206 |  | 
|  | 207 | .. code-block:: yaml | 
|  | 208 |  | 
|  | 209 | nginx: | 
|  | 210 | server: | 
|  | 211 | site: | 
|  | 212 | nginx_proxy_site02: | 
|  | 213 | enabled: true | 
| Niklaus Giger | 23096b2 | 2017-06-30 16:41:49 +0200 | [diff] [blame] | 214 | type: nginx_proxy | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 215 | 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 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 225 | Content filtering proxy: | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 226 |  | 
|  | 227 | .. code-block:: yaml | 
|  | 228 |  | 
|  | 229 | nginx: | 
|  | 230 | server: | 
|  | 231 | enabled: true | 
|  | 232 | site: | 
|  | 233 | nginx_proxy_site03: | 
|  | 234 | enabled: true | 
| Niklaus Giger | 23096b2 | 2017-06-30 16:41:49 +0200 | [diff] [blame] | 235 | type: nginx_proxy | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 236 | 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 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 248 | Proxy with access policy: | 
| Adam Tengler | e7746cb | 2016-04-27 19:01:25 +0200 | [diff] [blame] | 249 |  | 
|  | 250 | .. code-block:: yaml | 
|  | 251 |  | 
|  | 252 | nginx: | 
|  | 253 | server: | 
|  | 254 | site: | 
|  | 255 | nginx_proxy_site01: | 
|  | 256 | enabled: true | 
| Niklaus Giger | 23096b2 | 2017-06-30 16:41:49 +0200 | [diff] [blame] | 257 | type: nginx_proxy | 
| Adam Tengler | e7746cb | 2016-04-27 19:01:25 +0200 | [diff] [blame] | 258 | 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 |  | 
| Taras Khlivnyak | 2350166 | 2022-05-13 16:03:27 +0300 | [diff] [blame^] | 274 | Location with access policy: | 
|  | 275 |  | 
|  | 276 | .. note:: If location is defined and access_policy for location is defined, | 
|  | 277 | it overrides main access_policy for that location. | 
|  | 278 |  | 
|  | 279 | .. code-block:: yaml | 
|  | 280 |  | 
|  | 281 | nginx: | 
|  | 282 | server: | 
|  | 283 | site: | 
|  | 284 | nginx_proxy_site01: | 
|  | 285 | enabled: true | 
|  | 286 | type: nginx_proxy | 
|  | 287 | name: site01 | 
|  | 288 | access_policy: | 
|  | 289 | allow: | 
|  | 290 | - 192.168.1.1/24 | 
|  | 291 | - 127.0.0.1 | 
|  | 292 | deny: | 
|  | 293 | - 192.168.1.2 | 
|  | 294 | - all | 
|  | 295 | proxy: | 
|  | 296 | host: local.domain.com | 
|  | 297 | port: 80 | 
|  | 298 | protocol: http | 
|  | 299 | location: | 
|  | 300 | /internal/: | 
|  | 301 | host: 172.120.10.200 | 
|  | 302 | port: 80 | 
|  | 303 | protocol: http | 
|  | 304 | /restricted/: | 
|  | 305 | host: 172.10.10.200 | 
|  | 306 | port: 80 | 
|  | 307 | protocol: http | 
|  | 308 | access_policy: | 
|  | 309 | allow: | 
|  | 310 | - 10.10.10.0/24 | 
|  | 311 | - 127.0.0.1 | 
|  | 312 | deny: | 
|  | 313 | - all | 
|  | 314 | host: | 
|  | 315 | name: gitlab.domain.com | 
|  | 316 | port: 80 | 
|  | 317 |  | 
|  | 318 |  | 
|  | 319 |  | 
| Vasyl Saienko | c14eca2 | 2018-12-07 09:46:17 +0000 | [diff] [blame] | 320 | Use nginx `ngx_http_map_module` that creates variables whose values depend on | 
|  | 321 | values of other variables. | 
| Michel Nederlof | eb5dd23 | 2018-03-13 13:57:34 +0100 | [diff] [blame] | 322 |  | 
|  | 323 | .. code-block:: yaml | 
|  | 324 |  | 
| Vasyl Saienko | c14eca2 | 2018-12-07 09:46:17 +0000 | [diff] [blame] | 325 | nginx: | 
|  | 326 | server: | 
|  | 327 | enabled: true | 
|  | 328 | map: | 
|  | 329 | enabled: true | 
|  | 330 | items: | 
|  | 331 | mymap: | 
|  | 332 | enabled: true | 
|  | 333 | string: input_string | 
|  | 334 | variable: output_map_variable | 
|  | 335 | body: | 
|  | 336 | default: | 
|  | 337 | value: '""' | 
|  | 338 | example.com: | 
|  | 339 | value: '1' | 
|  | 340 | example.org: | 
|  | 341 | value: '2' | 
|  | 342 |  | 
|  | 343 | Use nginx `ngx_http_geo_module module` that creates variables with values | 
|  | 344 | depending on the client IP address. | 
|  | 345 |  | 
|  | 346 | .. code-block:: yaml | 
|  | 347 |  | 
|  | 348 | nginx: | 
|  | 349 | server: | 
|  | 350 | enabled: true | 
|  | 351 | geo: | 
|  | 352 | enabled: true | 
|  | 353 | items: | 
|  | 354 | my_geo_map: | 
|  | 355 | enabled: true | 
|  | 356 | variable: output_get_variable | 
|  | 357 | body: | 
|  | 358 | default: | 
|  | 359 | value: '""' | 
|  | 360 | cl1 | 
|  | 361 | name: 10.12.100.1/32 | 
|  | 362 | value: '1' | 
|  | 363 | cl2 | 
|  | 364 | name: 10.13.0.0/16 | 
|  | 365 | value:  2' | 
|  | 366 |  | 
|  | 367 | Use `ngx_http_limit_req_module` module that is used to limit the request | 
|  | 368 | processing rate per a defined key, in particular, the processing rate of | 
|  | 369 | requests coming from a single IP address. The limitation is done using | 
|  | 370 | the `leaky bucket` method. | 
|  | 371 | The `limit_req_module` might be configured globally or applied to specific | 
|  | 372 | nginx site. | 
|  | 373 |  | 
|  | 374 | .. code-block:: yaml | 
|  | 375 |  | 
|  | 376 | nginx: | 
|  | 377 | server: | 
|  | 378 | limit_req_module: | 
|  | 379 | limit_req_zone: | 
|  | 380 | global_limit_ip_zone: | 
|  | 381 | key: global_limit_ip_var | 
|  | 382 | size: 10m | 
|  | 383 | rate: '1r/s' | 
|  | 384 | limit_req_status: 503 | 
|  | 385 | limit_req: | 
|  | 386 | global_limit_zone: | 
|  | 387 | burst: 5 | 
|  | 388 | enabled: true | 
|  | 389 |  | 
|  | 390 | There is an example to to limit requests to all sites based on IP. | 
|  | 391 | In the following example all clients are limited except of 10.12.100.1 | 
|  | 392 | with 1 req per second. | 
|  | 393 |  | 
|  | 394 | #. Create geo instance that will match IP and set `limit_action` var. | 
|  | 395 | "0" - is unlimited, 1 - limited | 
|  | 396 |  | 
|  | 397 | #. Create a `global_geo_limiting_map` that will map `ip_limit_key` to | 
|  | 398 | `ip_limit_action` | 
|  | 399 |  | 
|  | 400 | #. Create global `limit_req_zone` called `global_limit_zone` that limits | 
|  | 401 | number of requests to 1r/s | 
|  | 402 |  | 
|  | 403 | #. Apply `global_limit_zone` globally to all requests with 5 req burst. | 
|  | 404 |  | 
|  | 405 | .. code-block:: yaml | 
|  | 406 |  | 
|  | 407 | nginx: | 
|  | 408 | server: | 
|  | 409 | enabled: true | 
|  | 410 | geo: | 
|  | 411 | enabled: true | 
|  | 412 | items: | 
|  | 413 | global_geo_limiting: | 
|  | 414 | enabled: true | 
|  | 415 | variable: ip_limit_key | 
|  | 416 | body: | 
|  | 417 | default: | 
|  | 418 | value: '1' | 
|  | 419 | unlimited_client1: | 
|  | 420 | name: '10.12.100.1/32' | 
|  | 421 | value: '0' | 
|  | 422 | map: | 
|  | 423 | enabled: true | 
|  | 424 | items: | 
|  | 425 | global_geo_limiting_map: | 
|  | 426 | enabled: true | 
|  | 427 | string: ip_limit_key | 
|  | 428 | variable: ip_limit_action | 
|  | 429 | body: | 
|  | 430 | limited: | 
|  | 431 | name: 1 | 
|  | 432 | value: '$binary_remote_addr' | 
|  | 433 | unlimited: | 
|  | 434 | name: 0 | 
|  | 435 | value: '""' | 
|  | 436 | limit_req_module: | 
|  | 437 | limit_req_zone: | 
|  | 438 | global_limit_zone: | 
|  | 439 | key: ip_limit_action | 
|  | 440 | size: 10m | 
|  | 441 | rate: '1r/s' | 
|  | 442 | limit_req_status: 503 | 
|  | 443 | limit_req: | 
|  | 444 | global_limit_zone: | 
|  | 445 | burst: 5 | 
|  | 446 | enabled: true | 
|  | 447 |  | 
|  | 448 | To apply request limiting to particular site only `limit_req` should be | 
|  | 449 | applied on site level, for example: | 
|  | 450 |  | 
|  | 451 | .. code-block:: yaml | 
|  | 452 |  | 
| Michel Nederlof | eb5dd23 | 2018-03-13 13:57:34 +0100 | [diff] [blame] | 453 | nginx: | 
|  | 454 | server: | 
|  | 455 | site: | 
| Vasyl Saienko | c14eca2 | 2018-12-07 09:46:17 +0000 | [diff] [blame] | 456 | nginx_proxy_openstack_api_keystone: | 
|  | 457 | limit_req_module: | 
|  | 458 | limit_req: | 
|  | 459 | global_limit_zone: | 
|  | 460 | burst: 5 | 
|  | 461 | enabled: true | 
|  | 462 |  | 
| Michel Nederlof | eb5dd23 | 2018-03-13 13:57:34 +0100 | [diff] [blame] | 463 |  | 
| Oleksandr Bryndzii | a26617c | 2018-12-07 17:36:42 +0000 | [diff] [blame] | 464 | Use `ngx_http_limit_conn_module` module that is used to set the shared memory | 
|  | 465 | zone and the maximum allowed number of connections for a given key value. | 
|  | 466 | The `limit_conn_module` might be configured globally or applied to specific | 
|  | 467 | nginx site. | 
|  | 468 |  | 
|  | 469 | .. code-block:: yaml | 
|  | 470 |  | 
|  | 471 | nginx: | 
|  | 472 | server: | 
|  | 473 | limit_conn_module: | 
|  | 474 | limit_conn_zone: | 
|  | 475 | global_limit_conn_zone: | 
|  | 476 | key: 'binary_remote_addr' | 
|  | 477 | size: 10m | 
|  | 478 | limit_conn_status: 503 | 
|  | 479 | limit_conn: | 
|  | 480 | global_limit_conn_zone: | 
|  | 481 | connection: 50 | 
|  | 482 | enabled: true | 
|  | 483 |  | 
|  | 484 |  | 
|  | 485 | To apply connection limiting to particular site only `limit_conn` should be | 
|  | 486 | applied on site level, for example: | 
|  | 487 |  | 
|  | 488 | .. code-block:: yaml | 
|  | 489 |  | 
|  | 490 | nginx: | 
|  | 491 | server: | 
|  | 492 | site: | 
|  | 493 | nginx_proxy_openstack_web: | 
|  | 494 | limit_conn_module: | 
|  | 495 | limit_conn: | 
|  | 496 | global_limit_conn_zone: | 
|  | 497 | connections: 25 | 
|  | 498 | enabled: true | 
|  | 499 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 500 | Gitlab server with user for basic auth: | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 501 |  | 
|  | 502 | .. code-block:: yaml | 
|  | 503 |  | 
|  | 504 | nginx: | 
|  | 505 | server: | 
|  | 506 | enabled: true | 
|  | 507 | user: | 
|  | 508 | username1: | 
|  | 509 | enabled: true | 
|  | 510 | password: magicunicorn | 
|  | 511 | htpasswd: htpasswd-site1 | 
|  | 512 | username2: | 
|  | 513 | enabled: true | 
|  | 514 | password: magicunicorn | 
|  | 515 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 516 | Proxy buffering: | 
| Ales Komarek | d77b797 | 2015-11-12 11:02:39 +0100 | [diff] [blame] | 517 |  | 
|  | 518 | .. code-block:: yaml | 
|  | 519 |  | 
|  | 520 | nginx: | 
|  | 521 | server: | 
|  | 522 | enabled: true | 
|  | 523 | bind: | 
|  | 524 | address: '0.0.0.0' | 
|  | 525 | ports: | 
|  | 526 | - 80 | 
|  | 527 | site: | 
|  | 528 | gitlab_proxy: | 
|  | 529 | enabled: true | 
| Niklaus Giger | 23096b2 | 2017-06-30 16:41:49 +0200 | [diff] [blame] | 530 | type: nginx_proxy | 
| Ales Komarek | d77b797 | 2015-11-12 11:02:39 +0100 | [diff] [blame] | 531 | proxy: | 
| Ondrej Smola | 5e177bc | 2017-12-07 12:55:23 +0100 | [diff] [blame] | 532 | request_buffer: false | 
| Ales Komarek | d77b797 | 2015-11-12 11:02:39 +0100 | [diff] [blame] | 533 | buffer: | 
|  | 534 | number: 8 | 
|  | 535 | size: 16 | 
|  | 536 | host: | 
|  | 537 | name: gitlab.domain.com | 
|  | 538 | port: 80 | 
|  | 539 |  | 
| Valeriy Sakharov | 4d8f3bf | 2021-07-02 14:40:51 +0400 | [diff] [blame] | 540 | If we need to read large client request headers, we need to add new | 
|  | 541 | parameter `large_client_header_buffers` with buffers number and size: | 
|  | 542 |  | 
|  | 543 | .. code-block:: yaml | 
|  | 544 |  | 
|  | 545 | nginx: | 
|  | 546 | server: | 
|  | 547 | enabled: true | 
|  | 548 | bind: | 
|  | 549 | address: '0.0.0.0' | 
|  | 550 | ports: | 
|  | 551 | - 80 | 
|  | 552 | site: | 
|  | 553 | gitlab_proxy: | 
|  | 554 | enabled: true | 
|  | 555 | type: nginx_proxy | 
|  | 556 | large_client_header_buffers: '4 8k' | 
|  | 557 | host: | 
|  | 558 | name: gitlab.domain.com | 
|  | 559 | port: 80 | 
|  | 560 |  | 
|  | 561 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 562 | Let's Encrypt: | 
| Michael Kutý | 3a5abf1 | 2015-12-04 21:03:33 +0100 | [diff] [blame] | 563 |  | 
|  | 564 | .. code-block:: yaml | 
|  | 565 |  | 
|  | 566 | nginx: | 
|  | 567 | server: | 
|  | 568 | enabled: true | 
|  | 569 | bind: | 
|  | 570 | address: '0.0.0.0' | 
|  | 571 | ports: | 
|  | 572 | - 443 | 
|  | 573 | site: | 
|  | 574 | gitlab_domain: | 
|  | 575 | enabled: true | 
|  | 576 | type: gitlab | 
|  | 577 | name: domain | 
|  | 578 | ssl: | 
|  | 579 | enabled: true | 
|  | 580 | engine: letsencrypt | 
|  | 581 | host: | 
|  | 582 | name: gitlab.domain.com | 
|  | 583 | port: 443 | 
|  | 584 |  | 
| Filip Pytloun | e0f7551 | 2016-11-03 14:34:26 +0100 | [diff] [blame] | 585 | SSL using already deployed key and cert file. | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 586 |  | 
|  | 587 | .. note:: The cert file should already contain CA cert and | 
|  | 588 | complete chain. | 
| Filip Pytloun | e0f7551 | 2016-11-03 14:34:26 +0100 | [diff] [blame] | 589 |  | 
|  | 590 | .. code-block:: yaml | 
|  | 591 |  | 
|  | 592 | nginx: | 
|  | 593 | server: | 
|  | 594 | enabled: true | 
|  | 595 | site: | 
|  | 596 | mysite: | 
|  | 597 | ssl: | 
|  | 598 | enabled: true | 
|  | 599 | key_file: /etc/ssl/private/mykey.key | 
|  | 600 | cert_file: /etc/ssl/cert/mycert.crt | 
|  | 601 |  | 
| Denis Egorenko | 3ecd88e | 2019-07-15 16:47:32 +0400 | [diff] [blame] | 602 | or | 
|  | 603 |  | 
|  | 604 | .. code-block:: yaml | 
|  | 605 |  | 
|  | 606 | nginx: | 
|  | 607 | server: | 
|  | 608 | enabled: true | 
|  | 609 | site: | 
|  | 610 | mysite: | 
|  | 611 | ssl: | 
|  | 612 | enabled: true | 
|  | 613 | engine: custom | 
|  | 614 | key_file: /etc/ssl/private/mykey.key | 
|  | 615 | cert_file: /etc/ssl/cert/mycert.crt | 
|  | 616 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 617 | Advanced SSL configuration, more information about SSL option | 
|  | 618 | may be found at http://nginx.org/en/docs/http/ngx_http_ssl_module.html | 
|  | 619 |  | 
|  | 620 | .. note:: Prior to nginx 1.11.0, only one type of ecdh curve | 
|  | 621 | can be applied in ``ssl_ecdh_curve directive``. | 
|  | 622 |  | 
|  | 623 | if mode = ``secure`` or mode = ``normal`` and ``ciphers`` | 
|  | 624 | or ``protocols`` are set, they should have type ``string``. | 
|  | 625 | If mode = ``manual``, their type should be ``dict`` | 
|  | 626 | as shown below. | 
| Vasyl Saienko | d3348f6 | 2018-02-09 20:08:01 +0200 | [diff] [blame] | 627 |  | 
|  | 628 | .. code-block:: yaml | 
|  | 629 |  | 
|  | 630 | nginx: | 
|  | 631 | server: | 
|  | 632 | enabled: true | 
|  | 633 | site: | 
|  | 634 | mysite: | 
|  | 635 | ssl: | 
|  | 636 | enabled: true | 
|  | 637 | mode: 'manual' | 
|  | 638 | key_file:  /srv/salt/pki/${_param:cluster_name}/${salt:minion:cert:proxy:common_name}.key | 
|  | 639 | cert_file: /srv/salt/pki/${_param:cluster_name}/${salt:minion:cert:proxy:common_name}.crt | 
|  | 640 | chain_file: /srv/salt/pki/${_param:cluster_name}/${salt:minion:cert:proxy:common_name}-with-chain.crt | 
|  | 641 | protocols: | 
|  | 642 | TLS1: | 
|  | 643 | name: 'TLSv1' | 
|  | 644 | enabled: True | 
|  | 645 | TLS1_1: | 
|  | 646 | name: 'TLSv1.1' | 
|  | 647 | enabled: True | 
|  | 648 | TLS1_2: | 
|  | 649 | name: 'TLSv1.2' | 
|  | 650 | enabled: False | 
|  | 651 | ciphers: | 
|  | 652 | ECDHE_RSA_AES256_GCM_SHA384: | 
|  | 653 | name: 'ECDHE-RSA-AES256-GCM-SHA384' | 
|  | 654 | enabled: True | 
|  | 655 | ECDHE_ECDSA_AES256_GCM_SHA384: | 
|  | 656 | name: 'ECDHE-ECDSA-AES256-GCM-SHA384' | 
|  | 657 | enabled: True | 
|  | 658 | buffer_size: '16k' | 
|  | 659 | crl: | 
|  | 660 | file: '/etc/ssl/crl.pem' | 
|  | 661 | enabled: False | 
|  | 662 | dhparam: | 
|  | 663 | enabled: True | 
|  | 664 | numbits: 2048 | 
| azvyagintsev | 57a85a1 | 2019-01-24 13:44:55 +0200 | [diff] [blame] | 665 | use_dsaparam: True | 
| Vasyl Saienko | d3348f6 | 2018-02-09 20:08:01 +0200 | [diff] [blame] | 666 | ecdh_curve: | 
|  | 667 | secp384r1: | 
|  | 668 | name: 'secp384r1' | 
|  | 669 | enabled: False | 
|  | 670 | secp521r1: | 
|  | 671 | name: 'secp521r1' | 
|  | 672 | enabled: True | 
|  | 673 | password_file: | 
|  | 674 | content: 'testcontent22' | 
|  | 675 | enabled: True | 
|  | 676 | file: '/etc/ssl/password.key' | 
|  | 677 | prefer_server_ciphers: 'on' | 
|  | 678 | ticket_key: | 
|  | 679 | enabled: True | 
|  | 680 | numbytes: 48 | 
|  | 681 | resolver: | 
|  | 682 | address: '127.0.0.1' | 
|  | 683 | valid_seconds: '500' | 
|  | 684 | timeout_seconds: '60' | 
|  | 685 | session_tickets: 'on' | 
|  | 686 | stapling: 'off' | 
|  | 687 | stapling_file: '/path/to/stapling/file' | 
|  | 688 | stapling_responder: 'http://ocsp.example.com/' | 
|  | 689 | stapling_verify: 'on' | 
|  | 690 | verify_client: 'on' | 
|  | 691 | client_certificate: | 
|  | 692 | file: '/etc/ssl/client_cert.pem' | 
|  | 693 | enabled: False | 
|  | 694 | verify_depth: 1 | 
|  | 695 | session_cache: 'shared:SSL:15m' | 
|  | 696 | session_timeout: '15m' | 
| Adam Tengler | 5c64af6 | 2018-06-22 12:17:55 +0000 | [diff] [blame] | 697 | strict_transport_security: | 
|  | 698 | max_age: 16000000 | 
|  | 699 | include_subdomains: False | 
|  | 700 | always: true | 
|  | 701 | enabled: true | 
| Vasyl Saienko | d3348f6 | 2018-02-09 20:08:01 +0200 | [diff] [blame] | 702 |  | 
| Vasyl Saienko | f5c57e2 | 2018-09-28 08:54:33 +0000 | [diff] [blame] | 703 | Setting custom proxy headers: | 
|  | 704 |  | 
|  | 705 | .. code-block:: yaml | 
|  | 706 |  | 
|  | 707 | nginx: | 
|  | 708 | server: | 
|  | 709 | enabled: true | 
|  | 710 | site: | 
|  | 711 | custom_headers: | 
|  | 712 | type: nginx_proxy | 
|  | 713 | proxy_set_header: | 
|  | 714 | Host: | 
|  | 715 | enabled: true | 
|  | 716 | value: "$host:8774" | 
|  | 717 | X-Real-IP: | 
|  | 718 | enabled: true | 
|  | 719 | value: '$remote_addr' | 
|  | 720 | X-Forwarded-For: | 
|  | 721 | enabled: true | 
|  | 722 | value: '$proxy_add_x_forwarded_for' | 
|  | 723 | X-Forwarded-Proto: | 
|  | 724 | enabled: true | 
|  | 725 | value: '$scheme' | 
|  | 726 | X-Forwarded-Port: | 
|  | 727 | enabled: true | 
|  | 728 | value: '$server_port' | 
|  | 729 |  | 
| Dzmitry Stremkouski | 1377246 | 2018-10-27 14:56:47 +0200 | [diff] [blame] | 730 | Define site catalog indexes: | 
|  | 731 |  | 
|  | 732 | .. code-block:: yaml | 
|  | 733 |  | 
|  | 734 | nginx: | 
|  | 735 | server: | 
|  | 736 | enabled: true | 
|  | 737 | site: | 
|  | 738 | nginx_catalog: | 
|  | 739 | enabled: true | 
|  | 740 | type: nginx_static | 
|  | 741 | name: server | 
|  | 742 | indexes: | 
|  | 743 | - index.htm | 
|  | 744 | - index.html | 
|  | 745 | host: | 
|  | 746 | name: 127.0.0.1 | 
|  | 747 | port: 80 | 
|  | 748 |  | 
|  | 749 | Define site catalog autoindex: | 
|  | 750 |  | 
|  | 751 | .. code-block:: yaml | 
|  | 752 |  | 
|  | 753 | nginx: | 
|  | 754 | server: | 
|  | 755 | enabled: true | 
|  | 756 | site: | 
|  | 757 | nginx_catalog: | 
|  | 758 | enabled: true | 
|  | 759 | type: nginx_static | 
|  | 760 | name: server | 
|  | 761 | autoindex: True | 
|  | 762 | host: | 
|  | 763 | name: 127.0.0.1 | 
|  | 764 | port: 80 | 
|  | 765 |  | 
|  | 766 | Nginx stats server (required by collectd nginx plugin) (DEPRECATED): | 
| Adam Tengler | c391657 | 2016-01-25 17:46:52 +0100 | [diff] [blame] | 767 |  | 
| Aleš Komárek | 296a844 | 2017-04-11 13:22:35 +0200 | [diff] [blame] | 768 | .. code-block:: yaml | 
| Adam Tengler | c391657 | 2016-01-25 17:46:52 +0100 | [diff] [blame] | 769 |  | 
|  | 770 | nginx: | 
|  | 771 | server: | 
|  | 772 | enabled: true | 
|  | 773 | site: | 
|  | 774 | nginx_stats_server: | 
|  | 775 | enabled: true | 
|  | 776 | type: nginx_stats | 
|  | 777 | name: server | 
|  | 778 | host: | 
|  | 779 | name: 127.0.0.1 | 
|  | 780 | port: 8888 | 
|  | 781 |  | 
| Dzmitry Stremkouski | 1377246 | 2018-10-27 14:56:47 +0200 | [diff] [blame] | 782 | or: | 
|  | 783 |  | 
|  | 784 | .. code-block:: yaml | 
|  | 785 |  | 
|  | 786 | nginx: | 
|  | 787 | server: | 
|  | 788 | enabled: true | 
|  | 789 | site: | 
|  | 790 | nginx_stats_server: | 
|  | 791 | enabled: true | 
|  | 792 | root: disabled | 
|  | 793 | indexes: [] | 
|  | 794 | stats: True | 
|  | 795 | type: nginx_static | 
|  | 796 | name: stat_server | 
|  | 797 | host: | 
|  | 798 | name: 127.0.0.1 | 
|  | 799 | address: 127.0.0.1 | 
|  | 800 | port: 8888 | 
|  | 801 |  | 
| OlgaGusarenko | e2f808f | 2018-07-30 23:42:18 +0300 | [diff] [blame] | 802 | Nginx configured to wait for another service/s before | 
|  | 803 | starting (currently only with systemd): | 
| Adam Tengler | 8689394 | 2018-06-20 14:06:24 +0000 | [diff] [blame] | 804 |  | 
|  | 805 | .. code-block:: yaml | 
|  | 806 |  | 
|  | 807 | nginx: | 
|  | 808 | server: | 
|  | 809 | wait_for_service: | 
|  | 810 | - foo-bar.mount | 
|  | 811 | enabled: true | 
|  | 812 | site: | 
|  | 813 | ... | 
|  | 814 |  | 
| Aleš Komárek | 296a844 | 2017-04-11 13:22:35 +0200 | [diff] [blame] | 815 | More Information | 
|  | 816 | ================ | 
| Filip Pytloun | 6b5bb65 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 817 |  | 
|  | 818 | * http://wiki.nginx.org/Main | 
|  | 819 | * https://wiki.mozilla.org/Security/Server_Side_TLS#Modern_compatibility | 
|  | 820 | * http://nginx.com/resources/admin-guide/reverse-proxy/ | 
|  | 821 | * https://mozilla.github.io/server-side-tls/ssl-config-generator/ |