You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.7 KiB

8 years ago
8 years ago
8 years ago
8 years ago
  1. # nginx-envtpl
  2. Nginx image with support for environment variables using [envtpl](https://github.com/andreasjansson/envtpl)
  3. ## Usage
  4. ```sh
  5. $ docker run -d -p 80:80 -e NGINX_WORKER_RLIMIT_NOFILE=... -v ./nginx.conf.tpl:/etc/nginx/nginx.conf.tpl schickling/nginx-envtpl
  6. ```
  7. ### Example `nginx.conf.tpl`
  8. ```nginx
  9. worker_processes auto;
  10. worker_rlimit_nofile {{ NGINX_WORKER_RLIMIT_NOFILE }};
  11. error_log /dev/stdout info;
  12. events {
  13. worker_connections {{ NGINX_WORKER_CONNECTIONS }};
  14. use epoll;
  15. multi_accept on;
  16. }
  17. http {
  18. proxy_cache_path /tmp/nginx levels=1:2 keys_zone=my_zone:10m inactive=60m;
  19. access_log /dev/stdout;
  20. server {
  21. listen 80 backlog={{ NGINX_BACKLOG }};
  22. root /usr/share/nginx/html/;
  23. index index.html;
  24. server_name localhost;
  25. charset utf-8;
  26. location / {
  27. proxy_pass {{ NGINX_PROXY_ADDR }};
  28. proxy_cache my_zone;
  29. proxy_cache_methods POST;
  30. proxy_cache_key "$request_uri|$request_body";
  31. proxy_cache_valid 5s;
  32. proxy_cache_use_stale error timeout updating;
  33. add_header X-Proxy-Cache $upstream_cache_status;
  34. }
  35. }
  36. }
  37. ```
  38. ### Alternative: Template via `$NGINX_CONFIG_TEMPLATE` environment variable
  39. Instead of mounting a `nginx.conf.tpl` file via a volume, you can also pass in the template via the `$NGINX_CONFIG_TEMPLATE` environment variable.
  40. Here is an `docker-compose.yml` example segment:
  41. ```yaml
  42. proxy:
  43. image: schickling/nginx-envtpl
  44. environment:
  45. NGINX_WORKER_RLIMIT_NOFILE: 96000
  46. NGINX_WORKER_CONNECTIONS: 10000
  47. NGINX_BACKLOG: 10000
  48. NGINX_PROXY_ADDR: "http://example.com/"
  49. NGINX_CONFIG_TEMPLATE: |
  50. worker_processes auto;
  51. worker_rlimit_nofile {{ NGINX_WORKER_RLIMIT_NOFILE }};
  52. error_log /dev/stdout info;
  53. events {
  54. worker_connections {{ NGINX_WORKER_CONNECTIONS }};
  55. use epoll;
  56. multi_accept on;
  57. }
  58. http {
  59. proxy_cache_path /tmp/nginx levels=1:2 keys_zone=my_zone:10m inactive=60m;
  60. access_log /dev/stdout;
  61. server {
  62. listen 80 backlog={{ NGINX_BACKLOG }};
  63. root /usr/share/nginx/html/;
  64. index index.html;
  65. server_name localhost;
  66. charset utf-8;
  67. location / {
  68. proxy_pass {{ NGINX_PROXY_ADDR }};
  69. proxy_cache my_zone;
  70. proxy_cache_methods POST;
  71. proxy_cache_key "$request_uri|$request_body";
  72. proxy_cache_valid 5s;
  73. proxy_cache_use_stale error timeout updating;
  74. add_header X-Proxy-Cache $upstream_cache_status;
  75. }
  76. }
  77. }
  78. ports:
  79. - "80:80"
  80. ```