Saltstack Official Nginx Formula
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

177 lines
4.6KB

  1. include:
  2. - nginx.common
  3. {% set nginx = pillar.get('nginx', {}) -%}
  4. {% set version = nginx.get('version', '1.5.2') -%}
  5. {% set checksum = nginx.get('checksum', 'sha1=3546be28a72251f8823ab6be6a1180d300d06f76') -%}
  6. {% set home = nginx.get('home', '/var/www') -%}
  7. {% set source = nginx.get('source_root', '/usr/local/src') -%}
  8. {% set nginx_package = source + '/nginx-' + version + '.tar.gz' -%}
  9. {% set nginx_home = home + "/nginx-" + version -%}
  10. {% set nginx_modules_dir = source + "/nginx-modules" -%}
  11. {% if nginx['with_luajit'] -%}
  12. include:
  13. - nginx.luajit2
  14. {% endif -%}
  15. {% if nginx['with_openresty'] -%}
  16. include:
  17. - nginx.openresty
  18. {% endif -%}
  19. nginx_group:
  20. group.present:
  21. - name: www-data
  22. nginx_user:
  23. file.directory:
  24. - name: {{ home }}
  25. - user: www-data
  26. - group: www-data
  27. - mode: 0755
  28. - require:
  29. - user: nginx_user
  30. - group: nginx_group
  31. user.present:
  32. - name: www-data
  33. - home: {{ home }}
  34. - groups:
  35. - www-data
  36. - require:
  37. - group: nginx_group
  38. get-nginx:
  39. pkg.installed:
  40. - names:
  41. - libpcre3-dev
  42. - build-essential
  43. - libssl-dev
  44. file.managed:
  45. - name: {{ nginx_package }}
  46. - source: http://nginx.org/download/nginx-{{ version }}.tar.gz
  47. - source_hash: {{ checksum }}
  48. cmd.wait:
  49. - cwd: {{ source }}
  50. - name: tar -zxf {{ nginx_package }} -C {{ home }}
  51. - require:
  52. - file: nginx_user
  53. - pkg: get-nginx
  54. - watch:
  55. - file: get-nginx
  56. {% for name, module in nginx.get('modules', {}).items() -%}
  57. get-nginx-{{name}}:
  58. file.managed:
  59. - name: {{ nginx_modules_dir }}/{{name}}.tar.gz
  60. - source: {{ module['source'] }}
  61. - source_hash: {{ module['source_hash'] }}
  62. - require:
  63. - file: nginx_user
  64. cmd.wait:
  65. - cwd: {{ nginx_home }}
  66. - names:
  67. - tar -zxf {{ nginx_modules_dir }}/{{name}}.tar.gz -C {{ nginx_modules_dir }}/{{name}}
  68. - watch:
  69. - file: get-nginx
  70. - require_in:
  71. - cmd: make-nginx
  72. {% endfor -%}
  73. get-ngx_devel_kit:
  74. file.managed:
  75. - name: {{ source }}/ngx_devel_kit.tar.gz
  76. - source: https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz
  77. - source_hash: sha1=e21ba642f26047661ada678b21eef001ee2121d8
  78. cmd.wait:
  79. - cwd: {{ nginx_home }}
  80. - name: tar -zxf {{ source }}/ngx_devel_kit.tar.gz -C {{ source }}
  81. - watch:
  82. - file: get-ngx_devel_kit
  83. get-lua-nginx-module:
  84. file.managed:
  85. - name: {{ source }}/lua-nginx-module.tar.gz
  86. - source: https://github.com/chaoslawful/lua-nginx-module/archive/v0.8.3rc1.tar.gz
  87. - source_hash: sha1=49b2fa946517fb2e9b26185d418570e98ff5ff51
  88. cmd.wait:
  89. - cwd: {{ nginx_home }}
  90. - name: tar -zxf {{ source }}/lua-nginx-module.tar.gz -C {{ source }}
  91. - watch:
  92. - file: get-lua-nginx-module
  93. {{ home }}:
  94. file.directory:
  95. - user: www-data
  96. - group: www-data
  97. - makedirs: True
  98. - mode: 0755
  99. {% for dir in ('body', 'proxy', 'fastcgi') -%}
  100. {{ home }}-{{dir}}:
  101. file.directory:
  102. - name: {{ home }}/{{dir}}
  103. - user: www-data
  104. - group: www-data
  105. - mode: 0755
  106. - require:
  107. - file: {{ home }}
  108. - require_in:
  109. - service: nginx
  110. {% endfor -%}
  111. nginx:
  112. cmd.wait:
  113. - cwd: {{ nginx_home }}
  114. - names:
  115. - ./configure --conf-path=/etc/nginx/nginx.conf
  116. --sbin-path=/usr/sbin/nginx
  117. --user=www-data
  118. --group=www-data
  119. --prefix=/usr/local/nginx
  120. --error-log-path=/var/log/nginx/error.log
  121. --pid-path=/var/run/nginx.pid
  122. --lock-path=/var/lock/nginx.lock
  123. --http-log-path=/var/log/nginx/access.log
  124. --with-http_dav_module
  125. --http-client-body-temp-path={{ home }}/body
  126. --http-proxy-temp-path={{ home }}/proxy
  127. --with-http_stub_status_module
  128. --http-fastcgi-temp-path={{ home }}/fastcgi
  129. --with-debug
  130. --with-http_ssl_module
  131. {% for name, module in nginx.get('modules', {}).items() -%}
  132. --add-module={{nginx_modules_dir}}/{{name}} \
  133. --with-pcre --with-ipv6
  134. {% endfor %}
  135. - make -j2 && make install
  136. - watch:
  137. - cmd: get-nginx
  138. - require:
  139. - cmd: get-nginx
  140. - cmd: get-lua-nginx-module
  141. - cmd: get-ngx_devel_kit
  142. - require_in:
  143. - service: nginx
  144. file.managed:
  145. - name: /etc/init/nginx.conf
  146. - template: jinja
  147. - user: root
  148. - group: root
  149. - mode: 440
  150. - source: salt://nginx/templates/upstart.jinja
  151. - require:
  152. - cmd: nginx
  153. service.running:
  154. - enable: True
  155. - watch:
  156. - file: nginx
  157. - file: /etc/nginx/nginx.conf
  158. - file: /etc/nginx/conf.d/default.conf
  159. - file: /etc/nginx/conf.d/example_ssl.conf
  160. - file: nginx
  161. - require:
  162. - cmd: nginx
  163. - file: {{ home }}