Saltstack Official Nginx Formula
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.

173 satır
4.6KB

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