├── .gitignore
├── .kitchen.docker.yml
├── .kitchen.yml
├── .rspec
├── .rubocop.yml
├── .travis.yml
├── .travis
└── dr_agon.pem.enc
├── Berksfile
├── CHANGELOG.md
├── CONTRIBUTING.md
├── Gemfile
├── LICENSE
├── README.md
├── TESTING.md
├── attributes
├── cleanup.rb
├── default.rb
└── logrotate.rb
├── chefignore
├── files
└── default
│ ├── mime.types
│ └── welcome-to-nginx.html
├── libraries
└── matchers.rb
├── metadata.rb
├── recipes
├── default.rb
└── official-repo.rb
├── resources
├── cleanup.rb
└── site_and_stream.rb
├── templates
└── default
│ ├── gzip.conf.erb
│ ├── logrotate-nginx.erb
│ ├── nginx.conf.erb
│ ├── nxdissite.erb
│ ├── nxensite.erb
│ └── some-handy-defaults.conf.erb
└── test
├── cookbooks
└── nginx_test
│ ├── .gitignore
│ ├── Berksfile
│ ├── CHANGELOG.md
│ ├── Gemfile
│ ├── LICENSE
│ ├── README.md
│ ├── attributes
│ ├── default.rb
│ └── logrotation.rb
│ ├── chefignore
│ ├── metadata.rb
│ ├── recipes
│ ├── cleaner_check.rb
│ ├── default.rb
│ ├── helper_templates.rb
│ └── streams.rb
│ └── templates
│ └── default
│ ├── frontend.conf.erb
│ └── test01.conf.erb
└── integration
└── default
└── inspec
├── helper_templates_spec.rb
├── logrotation_spec.rb
├── nginx_spec.rb
├── official_repo_spec.rb
├── shared_spec.rb
└── streams_spec.rb
/.gitignore:
--------------------------------------------------------------------------------
1 | *.swp
2 | metadata.json
3 |
4 | *~
5 | *#
6 | .#*
7 | \#*#
8 | .*.sw[a-z]
9 | *.un~
10 | pkg/
11 |
12 | # Berkshelf
13 | .vagrant
14 | /cookbooks
15 | Berksfile.lock
16 |
17 | # Bundler
18 | Gemfile.lock
19 | bin/*
20 | .bundle/*
21 |
22 |
23 | .kitchen/
--------------------------------------------------------------------------------
/.kitchen.docker.yml:
--------------------------------------------------------------------------------
1 | ---
2 | driver:
3 | name: docker
4 | use_sudo: false
5 | privileged: true
6 |
7 | provisioner:
8 | name: chef_zero
9 | chef_license: accept
10 |
11 | verifier:
12 | name: inspec
13 | inspec_tests:
14 | - path: test/integration/default/inspec
15 |
16 | platforms:
17 | - name: ubuntu-14.04-docker
18 | driver_config:
19 | image: ubuntu-upstart:14.04
20 | disable_upstart: false
21 | run_command: '/sbin/init'
22 | provision_command:
23 | - apt-get install -y net-tools gnupg # For InSpec & Chef
24 | - name: ubuntu-16.04-docker
25 | driver_config:
26 | image: ubuntu:16.04
27 | disable_upstart: false
28 | run_command: '/lib/systemd/systemd'
29 | provision_command:
30 | - apt-get install -y net-tools gnupg # For InSpec & Chef
31 | - systemctl set-default multi-user.target
32 | - name: ubuntu-18.04-docker
33 | driver_config:
34 | image: ubuntu:18.04
35 | disable_upstart: false
36 | run_command: '/lib/systemd/systemd'
37 | provision_command:
38 | - apt-get install -y net-tools gnupg # For InSpec & Chef
39 | - systemctl set-default multi-user.target
40 | - name: debian-8-docker
41 | driver_config:
42 | image: debian:8
43 | disable_upstart: false
44 | run_command: '/lib/systemd/systemd'
45 | provision_command:
46 | - apt-get install -y net-tools gnupg # For InSpec & Chef
47 | - systemctl set-default multi-user.target
48 | - name: debian-9-docker
49 | driver_config:
50 | image: debian:9
51 | disable_upstart: false
52 | run_command: '/lib/systemd/systemd'
53 | provision_command:
54 | - apt-get install -y net-tools gnupg # For InSpec & Chef
55 | - systemctl set-default multi-user.target
56 |
57 | suites:
58 | - name: chef-13
59 | attributes:
60 | nginx:
61 | config:
62 | mainconfig_include: "/etc/nginx/mainconfig_custom_include.conf"
63 | run_list:
64 | - recipe[apt]
65 | - recipe[nginx_lwrp::official-repo]
66 | - recipe[nginx_lwrp]
67 | - recipe[nginx_test::cleaner_check]
68 | - recipe[nginx_test]
69 | - recipe[nginx_test::helper_templates]
70 | - recipe[nginx_test::streams]
71 | provisioner:
72 | product_name: chef
73 | product_version: 13
74 | includes:
75 | - ubuntu-16.04-docker
76 | - name: chef-14
77 | attributes:
78 | nginx:
79 | config:
80 | mainconfig_include: "/etc/nginx/mainconfig_custom_include.conf"
81 | provisioner:
82 | product_name: chef
83 | product_version: 14
84 | run_list:
85 | - recipe[apt]
86 | - recipe[nginx_lwrp::official-repo]
87 | - recipe[nginx_lwrp]
88 | - recipe[nginx_test::cleaner_check]
89 | - recipe[nginx_test]
90 | - recipe[nginx_test::helper_templates]
91 | - recipe[nginx_test::streams]
92 | - name: chef-15
93 | attributes:
94 | nginx:
95 | config:
96 | mainconfig_include: "/etc/nginx/mainconfig_custom_include.conf"
97 | provisioner:
98 | product_name: chef
99 | product_version: 15
100 | run_list:
101 | - recipe[apt]
102 | - recipe[nginx_lwrp::official-repo]
103 | - recipe[nginx_lwrp]
104 | - recipe[nginx_test::cleaner_check]
105 | - recipe[nginx_test]
106 | - recipe[nginx_test::helper_templates]
107 | - recipe[nginx_test::streams]
108 |
109 |
--------------------------------------------------------------------------------
/.kitchen.yml:
--------------------------------------------------------------------------------
1 | ---
2 | driver:
3 | name: vagrant
4 |
5 | provisioner:
6 | name: chef_zero
7 | chef_license: accept
8 |
9 | verifier:
10 | name: inspec
11 | inspec_tests:
12 | - path: test/integration/default/inspec
13 |
14 | platforms:
15 | - name: ubuntu-14.04
16 | driver:
17 | box: bento/ubuntu-14.04
18 | - name: ubuntu-16.04
19 | driver:
20 | box: bento/ubuntu-16.04
21 | - name: ubuntu-18.04
22 | driver:
23 | box: bento/ubuntu-18.04
24 | - name: debian-8
25 | driver:
26 | box: bento/debian-8
27 | - name: debian-9
28 | driver:
29 | box: bento/debian-9
30 |
31 | suites:
32 | - name: chef-13
33 | attributes:
34 | nginx:
35 | config:
36 | mainconfig_include: "/etc/nginx/mainconfig_custom_include.conf"
37 | run_list:
38 | - recipe[apt]
39 | - recipe[nginx_lwrp::official-repo]
40 | - recipe[nginx_lwrp]
41 | - recipe[nginx_test::cleaner_check]
42 | - recipe[nginx_test]
43 | - recipe[nginx_test::helper_templates]
44 | - recipe[nginx_test::streams]
45 | provisioner:
46 | product_name: chef
47 | product_version: 13
48 | includes:
49 | - ubuntu-16.04
50 | - ubuntu-14.04
51 | - name: chef-14
52 | attributes:
53 | nginx:
54 | config:
55 | mainconfig_include: "/etc/nginx/mainconfig_custom_include.conf"
56 | provisioner:
57 | product_name: chef
58 | product_version: 14
59 | run_list:
60 | - recipe[apt]
61 | - recipe[nginx_lwrp::official-repo]
62 | - recipe[nginx_lwrp]
63 | - recipe[nginx_test::cleaner_check]
64 | - recipe[nginx_test]
65 | - recipe[nginx_test::helper_templates]
66 | - recipe[nginx_test::streams]
67 | - name: chef-15
68 | attributes:
69 | nginx:
70 | config:
71 | mainconfig_include: "/etc/nginx/mainconfig_custom_include.conf"
72 | provisioner:
73 | product_name: chef
74 | product_version: 15
75 | run_list:
76 | - recipe[apt]
77 | - recipe[nginx_lwrp::official-repo]
78 | - recipe[nginx_lwrp]
79 | - recipe[nginx_test::cleaner_check]
80 | - recipe[nginx_test]
81 | - recipe[nginx_test::helper_templates]
82 | - recipe[nginx_test::streams]
83 |
84 |
--------------------------------------------------------------------------------
/.rspec:
--------------------------------------------------------------------------------
1 | --color
2 | --format d
3 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | Metrics/BlockLength:
2 | Enabled: false
3 | Metrics/MethodLength:
4 | Enabled: false
5 | Naming/FileName:
6 | Enabled: false
7 | Style/AndOr:
8 | Enabled: false
9 | Style/FrozenStringLiteralComment:
10 | Enabled: false
11 | Style/MixinUsage:
12 | Enabled: false
13 | Style/TrailingCommaInArguments:
14 | EnforcedStyleForMultiline: consistent_comma
15 | Style/TrailingCommaInArrayLiteral:
16 | EnforcedStyleForMultiline: consistent_comma
17 | Style/TrailingCommaInHashLiteral:
18 | EnforcedStyleForMultiline: consistent_comma
19 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | services:
2 | - docker
3 |
4 | language: ruby
5 | cache: bundler
6 | sudo: false
7 | rvm:
8 | - 2.6.3
9 | bundler_args: "--without kitchen-vagrant"
10 |
11 | before_install:
12 | - gem update --system
13 | - gem install bundler
14 |
15 | script: "bundle exec kitchen test ${INSTANCE} --destroy=always"
16 |
17 | env:
18 | global:
19 | - KITCHEN_YAML=.kitchen.docker.yml
20 | matrix:
21 | - INSTANCE=chef-15-ubuntu-1804-docker
22 | - INSTANCE=chef-15-ubuntu-1604-docker
23 | - INSTANCE=chef-15-ubuntu-1404-docker
24 | - INSTANCE=chef-15-debian-9-docker
25 | - INSTANCE=chef-15-debian-8-docker
26 | - INSTANCE=chef-14-ubuntu-1804-docker
27 | - INSTANCE=chef-14-ubuntu-1604-docker
28 | - INSTANCE=chef-14-ubuntu-1404-docker
29 | - INSTANCE=chef-14-debian-9-docker
30 | - INSTANCE=chef-14-debian-8-docker
31 | - INSTANCE=chef-13-ubuntu-1604-docker
32 |
33 | jobs:
34 | include:
35 | - stage: lint
36 | script:
37 | - bundle exec rubocop --version
38 | - bundle exec rubocop .
39 | - bundle exec foodcritic --version
40 | - bundle exec foodcritic --contex --epic-fail any .
41 |
42 | - stage: deploy
43 | if: tag =~ ^v[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$
44 | script:
45 | - openssl aes-256-cbc -K $encrypted_f0160f5b72cb_key -iv $encrypted_f0160f5b72cb_iv -in .travis/dr_agon.pem.enc -out .travis/dr_agon.pem -d
46 | - bundle exec stove login --username dr_agon --key .travis/dr_agon.pem
47 | - bundle exec stove --no-git
48 |
--------------------------------------------------------------------------------
/.travis/dr_agon.pem.enc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evilmartians/chef-nginx/5f5d2ac1a211bdd6a73b07a8472ead519277a49d/.travis/dr_agon.pem.enc
--------------------------------------------------------------------------------
/Berksfile:
--------------------------------------------------------------------------------
1 | source 'https://supermarket.getchef.com'
2 |
3 | metadata
4 |
5 | group :integration do
6 | cookbook 'nginx_test', path: 'test/cookbooks/nginx_test'
7 | end
8 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # nginx_lwrp cookbook CHANGELOG
2 |
3 | ## 3.0.3 (2019-05-31)
4 |
5 | * Chef 15 support;
6 | * Ubuntu 18.04 support;
7 | * Test Kitchen: tests with Chef 15;
8 |
9 | ## 3.0.2 (2018-04-04)
10 |
11 | * Chef 14 support;
12 | * Test Kitchen: main tests are switched to Chef 14;
13 | * Test Kitchen: smoke test for Chef 13 was added;
14 | * Test Kitchen: second config file to run tests in Docker using TravisCI itself;
15 | * TravisCI integration & auto-deploy;
16 |
17 | ## 3.0.1 (2018-03-26)
18 |
19 | * TESTING.md file added to comply with supermarket validations.
20 | * Foodcritic FC117 & FC118 fixes.
21 |
22 | ## 3.0.0 (2018-03-20)
23 |
24 | * [Breaking change] **Chef 12 is not supported anymore**, see below for comments.
25 | * [Breaking change] no more `nginx_disable_cleanup` definition
26 | * [Breaking change] no more `nginx_logrotate` definition
27 | * Chef 13 support
28 | * cookbook name was changed to `nginx_lwrp` to add this cookbook to Supermarket.
29 | * new list of supported OSes:
30 | * Ubuntu 14.04
31 | * Ubuntu 16.04
32 | * Debian 8
33 | * Debian 9
34 | * LWRPs were rewritten using [new style](https://docs.chef.io/custom_resources.html)
35 | * Inspec is used instead of ServerSpec now
36 | * Gemfile update
37 | * Rubocop offences were fixed
38 | * Foodcritic offences were fixed
39 |
40 | Please be warned!!! Сhef 12 is reaching its EOL in April 2018 and will be removed from [downloads.chef.io](https://downloads.chef.io) so it doesn't make sense to continue its support, so I'm dropping Chef 12 support starting from version 3.0.0 of this cookbook in favor of Chef 13 support.
41 |
42 | ## 2.3.5 (2017-03-24)
43 |
44 | * nginx.conf template should accept `load_module` option.
45 |
46 | ## 2.3.4 (2016-11-02)
47 |
48 | * DH param file was renames to the expected one.
49 |
50 | ## 2.3.3 (2016-10-04)
51 |
52 | * Descent DH params file is generated after nginx package installation.
53 |
54 | ## 2.3.2 (2016-)
55 |
56 | * Test Kitchen: Debian 7 was added to the test suite.
57 | * `mainconfig_include_file` option was added.
58 | * Now using correct dummy template for config file for custom includes to main nginx config.
59 |
60 | ## 2.3.1 (2016-02-03)
61 |
62 | * Returned some back compatibility with Chef 11. As it was broken by me in previous release.
63 |
64 | ## 2.3.0 (2015-11-03)
65 |
66 | * New resource `nginx_streams`. Which uses the same provider as `nginx_sites` but manages `streams-available` & `streams-enabled` directories.
67 | * Provider `Chef::Provider::NginxSites` refactored to support logic for previously mentioned change.
68 |
69 | ## 2.2.7 (2015-06-07)
70 |
71 | * Bugfix: Making sure Nginx process is not stalled after initial installation.
72 |
73 | ## 2.2.6 (2015-06-07)
74 |
75 | * Issue #10 fix.
76 |
77 | ## 2.2.5 (2015-06-07)
78 |
79 | * Quotation marks around file modes in chef recipes.
80 | * New default mime type: woff2.
81 |
82 | ## 2.2.4
83 |
84 | * `recipe[nginx::official-repo]` that sets up official apt repository on Debian/Ubuntu.
85 | * First cookbook dependency `cookbook[apt]`
86 |
87 | ## 2.2.3
88 |
89 | * helper template with some handy default variables.
90 | * nginx logrotate accepts more options to be configured: `dateext` and `delaycompress`
91 | * gzip template default behaviour fix.
92 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | If you wish to contribute, please follow these steps:
2 |
3 | 1. Fork this repository on GitHub.
4 | 2. Create a new branch.
5 | 3. Write your code.
6 | 4. Write new tests.
7 | 5. Run `foodcritic -f any . && rubocop . && rspec && kitchen test`.
8 | 6. If everythig is Ok, commit and create a pull request.
9 |
10 | Thank you!
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'berkshelf'
4 |
5 | group :development do
6 | gem 'chefspec'
7 | gem 'foodcritic'
8 | gem 'inspec'
9 | gem 'ipaddr_extensions'
10 | gem 'kitchen-docker'
11 | gem 'kitchen-inspec'
12 | gem 'kitchen-vagrant'
13 | gem 'pry'
14 | gem 'rubocop'
15 | gem 'stove'
16 | gem 'test-kitchen'
17 | gem 'thor'
18 | gem 'vagrant-berkshelf'
19 | end
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2018, Kirill Kuznetsov
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/evilmartians/chef-nginx)
2 |
3 | # Description
4 |
5 | Installs Nginx from package, sets up some default configuration and defines LWRP supposed to be used inside your own cookbooks, which you use to manage your infrastructure.
6 |
7 | # Requirements
8 |
9 | ## Cookbooks
10 |
11 | At the moment this cookbook doesn't depend on other cookbooks but it may change in the future.
12 |
13 | ## Platform
14 |
15 | The cookbook has been tested to work on `Ubuntu 14.04`, `Ubuntu 16.04`, `Debian 8` and `Debian 9`
16 |
17 | I suppose it should also work for CenOS/RHEL but no tests have been conducted yet.
18 |
19 | ## Chef version
20 |
21 | Chef version >= `13` has to be used.
22 |
23 | > Сhef 12 is reaching its EOL in April 2018 and will be removed from [downloads.chef.io](https://downloads.chef.io) so it doesn't make sense to continue its support, so I'm dropping Chef 12 support starting from version 3.0.0 of this cookbook in favor of Chef 13.
24 |
25 | ## Attributes
26 |
27 | Defaults that are used to configure nginx. If you want to change one of this parameters in nginx consider using provided LWRP and definitions.
28 |
29 | * `node['nginx']['config']['conf_dir']` - Base nginx config directory. Default `/etc/nginx`.
30 | * `node['nginx']['config']['log_dir']` - Directory for nginx log files. Default `/var/log/nginx`.
31 | * `node['nginx']['config']['user']` - Default user that nginx will use to run worker processes. Default: `www-data`.
32 | * `node['nginx']['config']['worker_processes']` - Number of nginx workers. Default `cpu['total']`.
33 | * `node['nginx']['config']['worker_connections'] - Number of simultaneous connections that one worker can serve. Default `8192`.
34 | * `node['nginx']['config']['worker_rlimit_nofile']` - Specifies the value for maximum file descriptors that can be opened by one worker process. Default `8192`.
35 | * `node['nginx']['config']['pid']` - Path to Nginx pid file. Default: `/var/run/nginx.pid`
36 | * `node['nginx']['config']['mainconfig_include']` - Include files into the main context of nginx.conf. Default: `nil`
37 | * `node['nginx']['config']['error_log']` - Path to a default error log file. Default: `/var/log/nginx/error.log`
38 |
39 |
40 | # Recipes
41 |
42 | This cookbook provides only one recipe:
43 |
44 | ## default.rb
45 |
46 | This default recipe will make some basic steps:
47 |
48 | * installs Nginx from the package that is provided by your OS's package manager ("pin" the desired version using another cookbook);
49 | * creates all directories for configuration, directory for log files, etc;
50 | * creates default `nginx.conf` file and associated files;
51 | * configures log rotation for Nginx;
52 | * enables and starts Nginx service;
53 | * runs resource that removes Nginx configuration files for sites, which are not defined by this cookbook's LWRP.
54 |
55 | # Usage
56 |
57 | ## Wrapper-cookbook way
58 |
59 | This cookbook has been designed to provide **LWRP** for your own infrastructure recipes. First of all, we should make our infrastructure cookbook to load this one.
60 | * Do it by adding the line `depends nginx_lwrp` to your cookbook's metadata.rb.
61 | * To make all default preparations for using Nginx invoke `include_recipe "nginx_lwrp"` inside your designated recipe.
62 | * Now feel free to use all available LWRP provided by this cookbook.
63 |
64 | ## Roles-based way
65 |
66 | Another way to use this cookbook is just to add `recipe[nginx_lwrp]` to your **run_list** before your recipe, which is resonsible for your infrastructure.
67 |
68 | I personally prefer the first way because if you stick to it you'll eventually get complete and explicit "documentation" for your specific server installation. But in any case, you'll get Nginx installed, nginx.conf configured from the default template we provide, **LWRP** defined and ready to use.
69 |
70 | ## Official Nginx repo or default distro package
71 |
72 | If you would like to use nginx package from official nginx repo, then just add `recipe[nginx_lwrp::official-repo]` or `include_recipe 'nginx_lwrp::official-repo'` before `nginx_lwrp` recipe invokation. Other wise default nginx package would be used from distro repository.
73 |
74 | ## LWRP
75 |
76 | ### nginx_site
77 |
78 | This resource manages your Nginx sites configuraions.
79 |
80 | #### Actions
81 |
82 |
83 |
84 |
85 | Action |
86 | Description |
87 | Default |
88 |
89 |
90 |
91 |
92 | create |
93 |
94 | Creates site configuration file inside "sites-available" directory, but doesn't enable it.
95 | |
96 | |
97 |
98 |
99 | enable |
100 |
101 | Creates site configuration file inside "sites-available" directory, enables it (puts a symlink to it into "sites-enabled" directory)
102 | |
103 | Yes |
104 |
105 |
106 | disable |
107 |
108 | Ensures that site configuration file is disabled.
109 | |
110 | |
111 |
112 |
113 | delete |
114 |
115 | Disables and deletes site configuration file.
116 | |
117 | |
118 |
119 |
120 |
121 |
122 | #### Attributes
123 |
124 |
125 |
126 |
127 | Attribute |
128 | Description |
129 | Default Value |
130 |
131 |
132 |
133 |
134 | name |
135 | Name attribute: the name of the site's configuration file. |
136 | nil |
137 |
138 |
139 | template |
140 | Defines what erb template file from the cookbook that invokes this resource we should use. |
141 | name .conf.erb |
142 |
143 |
144 | variables |
145 | Variables to be used in the template. |
146 | Hash.new |
147 |
148 |
149 |
150 |
151 | #### Examples
152 |
153 |
154 |
155 | ```ruby
156 | # We want to use "example.com.conf.erb" template file, do not want to pass any variables.
157 | nginx_site 'example.com'
158 |
159 | # Using custom-named template file and passing some variables, which can be used inside the template.
160 | nginx_site 'forum.example.com' do
161 | action :enable
162 | template 'forum-nginx.erb'
163 | variables(
164 | listen_ip: '10.0.0.10',
165 | remote_ips: [ '10.0.0.2', '10.0.0.4' ]
166 | )
167 | end
168 |
169 | # Making sure that old site's configuration is disabled even if somebody has enabled it by hands.
170 | nginx_site 'old.example.com' do
171 | action :disable
172 | end
173 | ```
174 |
175 | ### nginx\_stream
176 |
177 | Resource is completle similar to `nginx_site` except it is made to manage stream section includes.
178 |
179 | #### Actions
180 |
181 |
182 |
183 |
184 | Action |
185 | Description |
186 | Default |
187 |
188 |
189 |
190 |
191 | create |
192 |
193 | Creates site configuration file inside "streams-available" directory, but doesn't enable it.
194 | |
195 | |
196 |
197 |
198 | enable |
199 |
200 | Creates site configuration file inside "streams-available" directory, enables it (puts a symlink to it into "streams-enabled" directory)
201 | |
202 | Yes |
203 |
204 |
205 | disable |
206 |
207 | Ensures that site configuration file is disabled.
208 | |
209 | |
210 |
211 |
212 | delete |
213 |
214 | Disables and deletes site configuration file.
215 | |
216 | |
217 |
218 |
219 |
220 |
221 | #### Attributes
222 |
223 |
224 |
225 |
226 | Attribute |
227 | Description |
228 | Default Value |
229 |
230 |
231 |
232 |
233 | name |
234 | Name attribute: the name of the stream's configuration file. |
235 | nil |
236 |
237 |
238 | template |
239 | Defines what erb template file from the cookbook that invokes this resource we should use. |
240 | name .conf.erb |
241 |
242 |
243 | variables |
244 | Variables to be used in the template. |
245 | Hash.new |
246 |
247 |
248 |
249 |
250 | #### Examples
251 |
252 | ```ruby
253 | # We want to use "example.com.conf.erb" template file, do not want to pass any variables.
254 | nginx_stream 'stream-01'
255 |
256 | # Using custom-named template file and passing some variables, which can be used inside the template.
257 | nginx_stream 'tcp-stream' do
258 | action :enable
259 | template 'nginx-stream.erb'
260 | variables(
261 | listen_ip: '10.0.0.10',
262 | remote_ips: '10.0.0.2'
263 | )
264 | end
265 |
266 | # Making sure that old site's configuration is disabled even if somebody has enabled it by hands.
267 | nginx_site 'old-stream' do
268 | action :disable
269 | end
270 | ```
271 |
272 | ### nginx\_mainconfig
273 |
274 | This resource is deprecated right now, use attributes instead.
275 |
276 | ```ruby
277 | node.default['nginx']['config']['OPTION'] = 'VALUE'
278 | ```
279 |
280 | #### List of allowed attributes
281 |
282 | * [accept_mutex](http://nginx.org/en/docs/ngx_core_module.html#accept_mutex)
283 | * [accept_mutex_delay](http://nginx.org/en/docs/ngx_core_module.html#accept_mutex_delay)
284 | * [daemon](http://nginx.org/en/docs/ngx_core_module.html#daemon)
285 | * [debug_points](http://nginx.org/en/docs/ngx_core_module.html#debug_points)
286 | * [error_log](http://nginx.org/en/docs/ngx_core_module.html#error_log)
287 | * [lock_file](http://nginx.org/en/docs/ngx_core_module.html#lock_file)
288 | * [master_process](http://nginx.org/en/docs/ngx_core_module.html#master_process)
289 | * [multi_accept](http://nginx.org/en/docs/ngx_core_module.html#multi_accept)
290 | * [pcre_jit](http://nginx.org/en/docs/ngx_core_module.html#pcre_jit)
291 | * [pid](http://nginx.org/en/docs/ngx_core_module.html#pid)
292 | * [server_names_hash_bucket_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_bucket_size)
293 | * [server_names_hash_max_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_max_size)
294 | * [ssl_engine](http://nginx.org/en/docs/ngx_core_module.html#ssl_engine)
295 | * [timer_resolution](http://nginx.org/en/docs/ngx_core_module.html#timer_resolution)
296 | * [types_hash_bucket_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#types_hash_bucket_size)
297 | * [use](http://nginx.org/en/docs/ngx_core_module.html#use)
298 | * [user](http://nginx.org/en/docs/ngx_core_module.html#user)
299 | * [variables_hash_bucket_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#variables_hash_bucket_size)
300 | * [variables_hash_max_size](http://nginx.org/en/docs/http/ngx_http_core_module.html#variables_hash_max_size)
301 | * [worker_connections](http://nginx.org/en/docs/ngx_core_module.html#worker_connections)
302 | * [worker_aio_requests](http://nginx.org/en/docs/ngx_core_module.html#worker_aio_requests)
303 | * [worker_cpu_affinity](http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity)
304 | * [worker_priority](http://nginx.org/en/docs/ngx_core_module.html#worker_priority)
305 | * [worker_processes](http://nginx.org/en/docs/ngx_core_module.html#worker_processes)
306 | * [worker_rlimit_core](http://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_core)
307 | * [worker_rlimit_nofile](http://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_nofile)
308 | * [worker_rlimit_sigpending](http://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_sigpending)
309 | * [working_directory](http://nginx.org/en/docs/ngx_core_module.html#working_directory)
310 |
311 | There are also attributes that can accept either a string or an array of strings:
312 |
313 | * [env](http://nginx.org/en/docs/ngx_core_module.html#env)
314 | * [load_module](http://nginx.org/en/docs/ngx_core_module.html#load_module)
315 | * [debug_connection](http://nginx.org/en/docs/ngx_core_module.html#debug_connection)
316 |
317 | ## Small handy templates
318 |
319 | As mentioned in the previous paragraph - main nginx config file acceps only limited set of options. But we always do some tuning like enabling compression, etc. I've created two small templates for a kind of configuration I usually use. It's a bit ugly and it's atemorary solution but may become usefull if you want some standart and clean confguration fast.
320 |
321 | **Invoke each of these templates only once otherwise you'll have invalid nginx config.**
322 |
323 | ### gzip.conf.erb
324 |
325 | Defaults to:
326 | ```
327 | gzip on;
328 | gzip_http_version 1.0;
329 | gzip_comp_level 4;
330 | gzip_proxied any;
331 | gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;
332 | gzip_disable msie6;
333 | gzip_vary off;
334 | ```
335 |
336 | How to use:
337 |
338 | ```ruby
339 | # Use its default parameters.
340 | nginx_site '00-gzip' do
341 | cookbook 'nginx_lwrp'
342 | template 'gzip.conf.erb'
343 | end
344 |
345 | # Or you can fine tune it.
346 | nginx_site '01-gzip' do
347 | cookbook 'nginx_lwrp'
348 | template 'gzip.conf.erb'
349 | variables(
350 | enabled: true,
351 | http_version: '1.0',
352 | comp_version: 4,
353 | proxied: 'any',
354 | types: %w( text/plain text/css ),
355 | vary: 'off'
356 | )
357 | end
358 | ```
359 |
360 | ### some-handy-defaults.conf.erb
361 |
362 | Defaults to:
363 |
364 | ```
365 | sendfile on;
366 | tcp_nopush on;
367 | tcp_nodelay on;
368 | server_tokens off;
369 | reset_timedout_connection off;
370 |
371 | keepalive_timeout 65;
372 | ```
373 |
374 | How to use:
375 |
376 | ```ruby
377 | # Use its default parameters.
378 | nginx_site '02-some-handy-defaults' do
379 | cookbook 'nginx_lwrp'
380 | template 'some-handy-defaults.conf.erb'
381 | end
382 |
383 | # Or you can fine tune it.
384 | nginx_site '03-some-handy-defaults' do
385 | cookbook 'nginx_lwrp'
386 | template 'some-handy-defaults.conf.erb'
387 | variables(
388 | sendfile: 'on',
389 | tcp_nopush: 'on',
390 | tcp_nodelay: 'on',
391 | server_tokens: 'off',
392 | reset_timedout_connection: 'off',
393 | keepalive_timeout: 65
394 | )
395 | end
396 | ```
397 |
398 | ### nginx\_logrotate
399 |
400 | This resource and definition are deprecated right now. There are new attributes for log rotation configuration now:
401 |
402 | ```ruby
403 | node.default['nginx']['logrotate']['OPTION'] = 'VALUE'
404 | ```
405 |
406 | Default logrotate configuration:
407 |
408 | ```
409 | /var/log/nginx/*.log {
410 | daily
411 | missingok
412 | notifempty
413 | rotate 7
414 | compress
415 | create 640 root adm
416 | delaycompress
417 | sharedscripts
418 | postrotate
419 | test -f /var/run/nginx.pid && kill -USR1 "$(cat /var/run/nginx.pid)"
420 | endscript
421 | }
422 | ```
423 |
424 | #### Attributes
425 |
426 |
427 |
428 |
429 | Attribute |
430 | Description |
431 | Default Value |
432 |
433 |
434 |
435 |
436 | logs |
437 | Log files to be rotated. Wildcards are allowed. |
438 | /var/log/nginx/*.log |
439 |
440 |
441 | how_often |
442 | Defines how often we should rotate logs. Allowed values are daily, weekly, monthly. |
443 | daily |
444 |
445 |
446 | copytruncate |
447 | If true truncate the original log file to zero size in place after creating a copy, instead of moving the old log file and optionally creating a new one. |
448 | false |
449 |
450 |
451 | dateext |
452 | If true archive old versions of log files adding a daily extension like YYYYMMDD instead of simply adding a number. The extension may be configured using the dateformat option. |
453 | false |
454 |
455 |
456 | delaycompress |
457 | If true postpone compression of the previous log file to the next rotation cycle. This only has effect when used in combination with compress. It can be used when some program cannot be told to close its logfile and thus might continue writing to the previous log file for some time. |
458 | true |
459 |
460 |
461 | rotate |
462 | Log files are rotated this number of times before being removed. |
463 | 7 |
464 |
465 |
466 | user |
467 | Specifies the user name who will own the log file. |
468 | root |
469 |
470 |
471 | group |
472 | Specifies the group the log file will belong to. |
473 | adm |
474 |
475 |
476 | mode |
477 | Specifies the mode for the log file in octal. |
478 | 640 |
479 |
480 |
481 | pidfile |
482 | Path to file that contains pid nuber of Nginx master process. If copytruncate is set to false we should send USR1 signal to that Nginx process to make it reopen log files after log rotation. |
483 | /var/run/nginx.pid |
484 |
485 |
486 |
487 |
488 | ### nginx\_disable\_cleanup
489 |
490 | This resource is deprecated right now.
491 |
492 | ### nginx\_logrotate\_template
493 |
494 | This resource is deprecated right now.
495 |
496 | ### nginx\_cleanup
497 |
498 | This definitions is deprecated right now. Use attribute to disable cleanup:
499 |
500 | ```ruby
501 | node.default['nginx']['enable_cleanup'] = false
502 | ```
503 |
504 | ## Sponsor
505 |
506 | [](https://evilmartians.com)
507 |
508 | # License and Author
509 |
510 | Kirill Kouznetsov (agon.smith@gmail.com)
511 |
512 | Copyright (C) 2012-2018 Kirill Kouznetsov
513 |
514 | Licensed under the Apache License, Version 2.0 (the "License");
515 | you may not use this file except in compliance with the License.
516 | You may obtain a copy of the License at
517 |
518 | http://www.apache.org/licenses/LICENSE-2.0
519 |
520 | Unless required by applicable law or agreed to in writing, software
521 | distributed under the License is distributed on an "AS IS" BASIS,
522 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
523 | See the License for the specific language governing permissions and
524 | limitations under the License.
525 |
--------------------------------------------------------------------------------
/TESTING.md:
--------------------------------------------------------------------------------
1 | To test this cookbook run:
2 |
3 | ```shell
4 |
5 | foodcritic -f any ./ && rubocop ./ && kitchen test
6 | ```
--------------------------------------------------------------------------------
/attributes/cleanup.rb:
--------------------------------------------------------------------------------
1 | default['nginx']['enable_cleanup'] = true
2 |
--------------------------------------------------------------------------------
/attributes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: nginx
3 | # Attributes:: default
4 | #
5 | # Author:: Kirill Kouznetsov
6 | #
7 | # Copyright 2012, Kirill Kouznetsov.
8 | #
9 | # Licensed under the Apache License, Version 2.0 (the "License");
10 | # you may not use this file except in compliance with the License.
11 | # You may obtain a copy of the License at
12 | #
13 | # http://www.apache.org/licenses/LICENSE-2.0
14 | #
15 | # Unless required by applicable law or agreed to in writing, software
16 | # distributed under the License is distributed on an "AS IS" BASIS,
17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | # See the License for the specific language governing permissions and
19 | # limitations under the License.
20 | #
21 |
22 | default['nginx']['config']['conf_dir'] = '/etc/nginx'
23 | default['nginx']['config']['log_dir'] = '/var/log/nginx'
24 | default['nginx']['config']['user'] = 'www-data'
25 | default['nginx']['config']['worker_processes'] = node['cpu']['total']
26 | default['nginx']['config']['pid'] = '/var/run/nginx.pid'
27 | default['nginx']['config']['worker_connections'] = 8192
28 | default['nginx']['config']['worker_rlimit_nofile'] = 8192
29 | default['nginx']['config']['mainconfig_include'] = nil
30 |
31 | default['nginx']['config']['error_log'] = ::File.join(
32 | node['nginx']['config']['log_dir'],
33 | 'error.log',
34 | )
35 |
36 | default['nginx']['dhparam']['size'] = 2048
37 |
38 | # vim: ts=2 sts=2 sw=2 sta et
39 |
--------------------------------------------------------------------------------
/attributes/logrotate.rb:
--------------------------------------------------------------------------------
1 | default['nginx']['logrotate']['logs'] = ::File.join(
2 | node['nginx']['config']['log_dir'],
3 | '*.log',
4 | )
5 | default['nginx']['logrotate']['how_often'] = 'daily'
6 | default['nginx']['logrotate']['rotate'] = '7'
7 | default['nginx']['logrotate']['copytruncate'] = false
8 | default['nginx']['logrotate']['user'] = 'root'
9 | default['nginx']['logrotate']['group'] = 'adm'
10 | default['nginx']['logrotate']['mode'] = '0640'
11 | default['nginx']['logrotate']['pidfile'] = node['nginx']['config']['pid']
12 | default['nginx']['logrotate']['dateext'] = false
13 | default['nginx']['logrotate']['delaycompress'] = true
14 |
--------------------------------------------------------------------------------
/chefignore:
--------------------------------------------------------------------------------
1 | # Put files/directories that should be ignored in this file when uploading
2 | # to a chef-server or supermarket.
3 | # Lines that start with '# ' are comments.
4 |
5 | # OS generated files #
6 | ######################
7 | .DS_Store
8 | Icon?
9 | nohup.out
10 | ehthumbs.db
11 | Thumbs.db
12 |
13 | # SASS #
14 | ########
15 | .sass-cache
16 |
17 | # EDITORS #
18 | ###########
19 | \#*
20 | .#*
21 | *~
22 | *.sw[a-z]
23 | *.bak
24 | REVISION
25 | TAGS*
26 | tmtags
27 | *_flymake.*
28 | *_flymake
29 | *.tmproj
30 | .project
31 | .settings
32 | mkmf.log
33 |
34 | ## COMPILED ##
35 | ##############
36 | a.out
37 | *.o
38 | *.pyc
39 | *.so
40 | *.com
41 | *.class
42 | *.dll
43 | *.exe
44 | */rdoc/
45 |
46 | # Testing #
47 | ###########
48 | .watchr
49 | .rspec
50 | spec/*
51 | spec/fixtures/*
52 | test/*
53 | features/*
54 | examples/*
55 | Guardfile
56 | Procfile
57 | .kitchen*
58 | .rubocop.yml
59 | spec/*
60 | Rakefile
61 | .travis.yml
62 | .foodcritic
63 | .codeclimate.yml
64 |
65 | # SCM #
66 | #######
67 | .git
68 | */.git
69 | .gitignore
70 | .gitmodules
71 | .gitconfig
72 | .gitattributes
73 | .svn
74 | */.bzr/*
75 | */.hg/*
76 | */.svn/*
77 |
78 | # Berkshelf #
79 | #############
80 | Berksfile
81 | Berksfile.lock
82 | cookbooks/*
83 | tmp
84 |
85 | # Policyfile #
86 | ##############
87 | Policyfile.rb
88 | Policyfile.lock.json
89 |
90 | # Cookbooks #
91 | #############
92 | CONTRIBUTING*
93 | CHANGELOG*
94 | TESTING*
95 | MAINTAINERS.toml
96 |
97 | # Strainer #
98 | ############
99 | Colanderfile
100 | Strainerfile
101 | .colander
102 | .strainer
103 |
104 | # Vagrant #
105 | ###########
106 | .vagrant
107 | Vagrantfile
108 |
--------------------------------------------------------------------------------
/files/default/mime.types:
--------------------------------------------------------------------------------
1 | types {
2 | text/html html htm shtml;
3 | text/css css;
4 | text/xml xml;
5 | image/gif gif;
6 | image/jpeg jpeg jpg;
7 | application/x-javascript js;
8 | application/json json;
9 | application/atom+xml atom;
10 | application/rss+xml rss;
11 |
12 | text/mathml mml;
13 | text/plain txt;
14 | text/vnd.sun.j2me.app-descriptor jad;
15 | text/vnd.wap.wml wml;
16 | text/x-component htc;
17 |
18 | image/png png;
19 | image/tiff tif tiff;
20 | image/vnd.wap.wbmp wbmp;
21 | image/x-icon ico;
22 | image/x-jng jng;
23 | image/x-ms-bmp bmp;
24 | image/svg+xml svg svgz;
25 | image/webp webp;
26 |
27 | application/font-woff woff;
28 | application/font-woff2 woff2;
29 | application/java-archive jar war ear;
30 | application/mac-binhex40 hqx;
31 | application/msword doc;
32 | application/pdf pdf;
33 | application/postscript ps eps ai;
34 | application/rtf rtf;
35 | application/vnd.ms-excel xls;
36 | application/vnd.ms-fontobject eot;
37 | application/vnd.ms-powerpoint ppt;
38 | application/vnd.wap.wmlc wmlc;
39 | application/vnd.google-earth.kml+xml kml;
40 | application/vnd.google-earth.kmz kmz;
41 | application/x-7z-compressed 7z;
42 | application/x-cocoa cco;
43 | application/x-font-ttf ttf;
44 | application/x-java-archive-diff jardiff;
45 | application/x-java-jnlp-file jnlp;
46 | application/x-makeself run;
47 | application/x-perl pl pm;
48 | application/x-pilot prc pdb;
49 | application/x-rar-compressed rar;
50 | application/x-redhat-package-manager rpm;
51 | application/x-sea sea;
52 | application/x-shockwave-flash swf;
53 | application/x-stuffit sit;
54 | application/x-tcl tcl tk;
55 | application/x-x509-ca-cert der pem crt;
56 | application/x-xpinstall xpi;
57 | application/xhtml+xml xhtml;
58 | application/zip zip;
59 |
60 | application/octet-stream bin exe dll;
61 | application/octet-stream deb;
62 | application/octet-stream dmg;
63 | application/octet-stream iso img;
64 | application/octet-stream msi msp msm;
65 |
66 | audio/midi mid midi kar;
67 | audio/mpeg mp3;
68 | audio/ogg ogg;
69 | audio/x-m4a m4a;
70 | audio/x-realaudio ra;
71 |
72 | video/3gpp 3gpp 3gp;
73 | video/mp4 mp4;
74 | video/mpeg mpeg mpg;
75 | video/quicktime mov;
76 | video/webm webm;
77 | video/x-flv flv;
78 | video/x-m4v m4v;
79 | video/x-mng mng;
80 | video/x-ms-asf asx asf;
81 | video/x-ms-wmv wmv;
82 | video/x-msvideo avi;
83 | }
84 |
--------------------------------------------------------------------------------
/files/default/welcome-to-nginx.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Welcome to nginx!
4 |
5 |
6 | Welcome to nginx!
7 |
8 |
9 |
--------------------------------------------------------------------------------
/libraries/matchers.rb:
--------------------------------------------------------------------------------
1 | if defined?(ChefSpec)
2 | def add_nginx_site(resource_name)
3 | ChefSpec::Matchers::ResourceMatcher.new(
4 | :nginx_site,
5 | :create,
6 | resource_name,
7 | )
8 | end
9 |
10 | def remove_nginx_site(resource_name)
11 | ChefSpec::Matchers::ResourceMatcher.new(
12 | :nginx_site,
13 | :delete,
14 | resource_name,
15 | )
16 | end
17 |
18 | def enable_nginx_site(resource_name)
19 | ChefSpec::Matchers::ResourceMatcher.new(
20 | :nginx_site,
21 | :enable,
22 | resource_name,
23 | )
24 | end
25 |
26 | def disable_nginx_site(resource_name)
27 | ChefSpec::Matchers::ResourceMatcher.new(
28 | :nginx_site,
29 | :disable,
30 | resource_name,
31 | )
32 | end
33 |
34 | def add_nginx_stream(resource_name)
35 | ChefSpec::Matchers::ResourceMatcher.new(
36 | :nginx_stream,
37 | :create,
38 | resource_name,
39 | )
40 | end
41 |
42 | def remove_nginx_stream(resource_name)
43 | ChefSpec::Matchers::ResourceMatcher.new(
44 | :nginx_stream,
45 | :delete,
46 | resource_name,
47 | )
48 | end
49 |
50 | def enable_nginx_stream(resource_name)
51 | ChefSpec::Matchers::ResourceMatcher.new(
52 | :nginx_stream,
53 | :enable,
54 | resource_name,
55 | )
56 | end
57 |
58 | def disable_nginx_stream(resource_name)
59 | ChefSpec::Matchers::ResourceMatcher.new(
60 | :nginx_stream,
61 | :disable,
62 | resource_name,
63 | )
64 | end
65 |
66 | def enable_nginx_logrotate_template(resource_name)
67 | ChefSpec::Matchers::ResourceMatcher.new(
68 | :nginx_logrotate_template,
69 | :enable,
70 | resource_name,
71 | )
72 | end
73 |
74 | def disable_nginx_logrotate_template(resource_name)
75 | ChefSpec::Matchers::ResourceMatcher.new(
76 | :nginx_logrotate_template,
77 | :disable,
78 | resource_name,
79 | )
80 | end
81 |
82 | def run_nginx_cleanup(resource_name)
83 | ChefSpec::Matchers::ResourceMatcher.new(:nginx_cleanup, :run, resource_name)
84 | end
85 |
86 | def disable_nginx_cleanup(resource_name)
87 | ChefSpec::Matchers::ResourceMatcher.new(
88 | :nginx_cleanup,
89 | :disable,
90 | resource_name,
91 | )
92 | end
93 | end
94 |
--------------------------------------------------------------------------------
/metadata.rb:
--------------------------------------------------------------------------------
1 | name 'nginx_lwrp'
2 | maintainer 'Kirill Kouznetsov'
3 | maintainer_email 'agon.smith@gmail.com'
4 | license 'Apache-2.0'
5 | description 'Installs and configures nginx'
6 | version '3.0.3'
7 |
8 | depends 'apt'
9 |
10 | supports 'ubuntu', '>= 14.04'
11 | supports 'debian', '>= 8.0'
12 |
13 | chef_version '>= 13.0', '< 16.0'
14 |
15 | source_url 'https://github.com/evilmartians/chef-nginx'
16 | issues_url 'https://github.com/evilmartians/chef-nginx/issues'
17 |
--------------------------------------------------------------------------------
/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: nginx
3 | # Recipe:: default
4 | #
5 | # Author:: Kirill Kouznetsov
6 | #
7 | # Copyright 2018, Kirill Kouznetsov.
8 | #
9 | # Licensed under the Apache License, Version 2.0 (the "License");
10 | # you may not use this file except in compliance with the License.
11 | # You may obtain a copy of the License at
12 | #
13 | # http://www.apache.org/licenses/LICENSE-2.0
14 | #
15 | # Unless required by applicable law or agreed to in writing, software
16 | # distributed under the License is distributed on an "AS IS" BASIS,
17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | # See the License for the specific language governing permissions and
19 | # limitations under the License.
20 | #
21 |
22 | begin
23 | all_res = run_context.resource_collection.all_resources
24 |
25 | recipe_res_collection = all_res.select do |res|
26 | res.cookbook_name == cookbook_name && res.recipe_name == 'default'
27 | end
28 |
29 | Chef::Log.debug(
30 | format(
31 | 'Resources found inside recipe[%s::%s]: %s',
32 | cookbook: cookbook_name,
33 | recipe: recipe_name,
34 | resources: recipe_res_collection.length,
35 | ),
36 | )
37 | raise Chef::Exceptions::ResourceNotFound if recipe_res_collection.empty?
38 | rescue Chef::Exceptions::ResourceNotFound
39 | package 'logrotate'
40 | package 'nginx'
41 |
42 | # We stop nginx right after the installation to make the first configuration.
43 | # We will make sure it starts with the dummy delay resource below.
44 | service 'nginx' do
45 | action :enable if node['platform'] == 'ubuntu' and
46 | node['platform_version'].to_f < 16.04
47 | subscribes :stop, 'package[nginx]', :immediately
48 | end
49 |
50 | directory node['nginx']['config']['log_dir'] do
51 | mode '0755'
52 | owner node['nginx']['config']['user']
53 | action :create
54 | end
55 |
56 | %w[nxensite nxdissite].each do |nxscript|
57 | template "/usr/sbin/#{nxscript}" do
58 | source "#{nxscript}.erb"
59 | mode '0755'
60 | owner 'root'
61 | group 'root'
62 | end
63 | end
64 |
65 | %w[
66 | sites-available
67 | sites-enabled
68 | streams-available
69 | streams-enabled
70 | conf.d
71 | ].each do |dir|
72 | directory dir do
73 | path "#{node['nginx']['config']['conf_dir']}/#{dir}/"
74 | owner 'root'
75 | group 'root'
76 | mode '0755'
77 | end
78 | end
79 |
80 | # Temporary fix:
81 | # conf.d/default.conf
82 | # conf.d/example_ssl.conf
83 | # These files are installed automatically from nginx package. They
84 | # may create a conflict with your actual configuration.g
85 | %w[default example_ssl].each do |f|
86 | file "#{node['nginx']['config']['conf_dir']}/conf.d/#{f}.conf" do
87 | action :delete
88 | end
89 | end
90 |
91 | directory '/var/www/' do
92 | path '/var/www/'
93 | owner 'root'
94 | group 'root'
95 | mode '0755'
96 | end
97 |
98 | cookbook_file '/var/www/index.html' do
99 | action :create_if_missing
100 | source 'welcome-to-nginx.html'
101 | end
102 |
103 | dh_param_path = "#{node['nginx']['config']['conf_dir']}/dhparam.pem"
104 | dh_param_size = node['nginx']['dhparam']['size']
105 |
106 | execute 'Generate descent DH param file.' do
107 | command "openssl dhparam -out #{dh_param_path} #{dh_param_size}"
108 | creates dh_param_path
109 | action :run
110 | notifies :reload, 'service[nginx]', :delayed
111 | end
112 |
113 | template 'Nginx main configuration file' do
114 | path "#{node['nginx']['config']['conf_dir']}/nginx.conf"
115 | source 'nginx.conf.erb'
116 | owner 'root'
117 | group 'root'
118 | variables(options: Mash.new(node['nginx']['config']))
119 |
120 | # Start nginx if not started and reload otherwise.
121 | notifies :start, 'service[nginx]', :delayed
122 | notifies :reload, 'service[nginx]', :delayed
123 |
124 | # see dummy delay resource below.
125 | action :nothing
126 | end
127 |
128 | cookbook_file "#{node['nginx']['config']['conf_dir']}/mime.types" do
129 | owner 'root'
130 | group 'root'
131 | mode '0644'
132 | source 'mime.types'
133 | notifies :reload, 'service[nginx]', :delayed
134 | end
135 |
136 | nginx_cleanup node['nginx']['config']['conf_dir'] do
137 | action :nothing
138 | notifies :reload, 'service[nginx]', :delayed
139 | only_if { node['nginx']['enable_cleanup'] }
140 | end
141 |
142 | template '/etc/logrotate.d/nginx' do
143 | owner 'root'
144 | group 'root'
145 | source 'logrotate-nginx.erb'
146 | variables(
147 | logs: node['nginx']['logrotate']['logs'],
148 | how_often: node['nginx']['logrotate']['how_often'],
149 | rotate: node['nginx']['logrotate']['rotate'],
150 | copytruncate: node['nginx']['logrotate']['copytruncate'],
151 | user: node['nginx']['logrotate']['user'],
152 | group: node['nginx']['logrotate']['group'],
153 | mode: node['nginx']['logrotate']['mode'],
154 | pidfile: node['nginx']['logrotate']['pidfile'],
155 | dateext: node['nginx']['logrotate']['dateext'],
156 | delaycompress: node['nginx']['logrotate']['delaycompress'],
157 | )
158 | end
159 |
160 | bash 'custom delay for some resouces' do
161 | code 'true'
162 |
163 | # We want cleanup to happen after all resource invocations from recipes.
164 | notifies :run,
165 | "nginx_cleanup[#{node['nginx']['config']['conf_dir']}]",
166 | :delayed
167 |
168 | # Delaying nginx.conf creation to help nginx_stream resources enable
169 | # streams directories includes.
170 | notifies :create, 'template[Nginx main configuration file]', :delayed
171 | end
172 | end
173 |
--------------------------------------------------------------------------------
/recipes/official-repo.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: nginx
3 | # Recipe:: official-repo
4 | #
5 | # Author:: Kirill Kouznetsov
6 | #
7 | # Copyright 2018, Kirill Kouznetsov.
8 | #
9 | # Licensed under the Apache License, Version 2.0 (the "License");
10 | # you may not use this file except in compliance with the License.
11 | # You may obtain a copy of the License at
12 | #
13 | # http://www.apache.org/licenses/LICENSE-2.0
14 | #
15 | # Unless required by applicable law or agreed to in writing, software
16 | # distributed under the License is distributed on an "AS IS" BASIS,
17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | # See the License for the specific language governing permissions and
19 | # limitations under the License.
20 | #
21 |
22 | apt_repository 'nginx' do
23 | uri "http://nginx.org/packages/mainline/#{node['platform']}/"
24 | distribution node['lsb']['codename']
25 | components ['nginx']
26 | key 'http://nginx.org/keys/nginx_signing.key'
27 | only_if { node['platform_family'] == 'debian' }
28 | end
29 |
--------------------------------------------------------------------------------
/resources/cleanup.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: nginx
3 | # Resource:: cleanup
4 | #
5 | # Author:: Kirill Kouznetsov
6 | #
7 | # Copyright 2018, Kirill Kouznetsov.
8 | #
9 | # Licensed under the Apache License, Version 2.0 (the "License");
10 | # you may not use this file except in compliance with the License.
11 | # You may obtain a copy of the License at
12 | #
13 | # http://www.apache.org/licenses/LICENSE-2.0
14 | #
15 | # Unless required by applicable law or agreed to in writing, software
16 | # distributed under the License is distributed on an "AS IS" BASIS,
17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | # See the License for the specific language governing permissions and
19 | # limitations under the License.
20 | #
21 |
22 | resource_name :nginx_cleanup
23 |
24 | default_action :run
25 |
26 | property :path, String, name_property: true
27 |
28 | action :run do
29 | valid_files = list_defined_resources(
30 | new_resource.path,
31 | run_context.parent_run_context,
32 | )
33 | file_list = ::Dir.glob(::File.join(new_resource.path, '*-enabled', '*'))
34 |
35 | kill_them_with_fire = file_list - valid_files
36 |
37 | kill_them_with_fire.each do |file|
38 | Chef::Log.info(
39 | "Nginx configuration '#{file}' is not managed by Chef. Disabling it.",
40 | )
41 | ::File.unlink file
42 | end
43 | end
44 |
45 | private
46 |
47 | action_class.class_eval do
48 | private
49 |
50 | def list_defined_resources(path, run_context)
51 | res_list = run_context.resource_collection.all_resources.select do |res|
52 | res.resource_name == :nginx_lwrp_site_and_stream
53 | end
54 | res_list.map do |res|
55 | ::File.join(
56 | path,
57 | "#{res.declared_type.to_s.split('_')[1]}s-enabled",
58 | "#{res.name}.conf",
59 | )
60 | end
61 | end
62 | end
63 |
--------------------------------------------------------------------------------
/resources/site_and_stream.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: nginx
3 | # Resource:: site
4 | # Resource:: stream
5 | #
6 | # Author:: Kirill Kouznetsov
7 | #
8 | # Copyright 2018, Kirill Kouznetsov.
9 | #
10 | # Licensed under the Apache License, Version 2.0 (the "License");
11 | # you may not use this file except in compliance with the License.
12 | # You may obtain a copy of the License at
13 | #
14 | # http://www.apache.org/licenses/LICENSE-2.0
15 | #
16 | # Unless required by applicable law or agreed to in writing, software
17 | # distributed under the License is distributed on an "AS IS" BASIS,
18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | # See the License for the specific language governing permissions and
20 | # limitations under the License.
21 | #
22 |
23 | provides :nginx_site
24 | provides :nginx_stream
25 |
26 | default_action :enable
27 |
28 | property :template, String
29 | property :variables, Hash, default: {}
30 | property :cookbook, String
31 |
32 | def to_s
33 | "#{declared_type}[#{name}]"
34 | end
35 |
36 | action_class.class_eval do
37 | def load_current_resource
38 | conf_dir = node['nginx']['config']['conf_dir']
39 | prefix = case new_resource.declared_type
40 | when :nginx_site
41 | 'sites'
42 | when :nginx_stream
43 | 'streams'
44 | end
45 |
46 | @config = ::File.join(
47 | conf_dir,
48 | "#{prefix}-available",
49 | "#{new_resource.name}.conf",
50 | )
51 |
52 | @symlink = ::File.join(
53 | conf_dir,
54 | "#{prefix}-enabled",
55 | "#{new_resource.name}.conf",
56 | )
57 | end
58 | end
59 |
60 | action :create do
61 | unless ::File.exist? @config
62 | Chef::Log.info("Creating #{new_resource} config.")
63 | end
64 |
65 | template_file = if new_resource.template.nil? or new_resource.template.empty?
66 | "#{new_resource.name}.conf.erb"
67 | else
68 | new_resource.template
69 | end
70 |
71 | if ::File.symlink? @symlink
72 | declare_resource(:template, @config) do
73 | action :create
74 | mode '0644'
75 | owner 'root'
76 | group 'root'
77 | source template_file
78 | cookbook new_resource.cookbook if new_resource.cookbook
79 | variables new_resource.variables
80 | notifies :reload, 'service[nginx]', :delayed
81 | end
82 | else
83 | declare_resource(:template, @config) do
84 | action :create
85 | mode '0644'
86 | owner 'root'
87 | group 'root'
88 | source template_file
89 | cookbook new_resource.cookbook if new_resource.cookbook
90 | variables new_resource.variables
91 | end
92 | end
93 | end
94 |
95 | action :enable do
96 | unless ::File.symlink? @symlink
97 | Chef::Log.info("Enabling #{new_resource} config.")
98 | end
99 |
100 | action_create
101 |
102 | resources = run_context.parent_run_context.resource_collection
103 |
104 | if new_resource.declared_type == :nginx_stream
105 | nginx_main_config_template = resources.find(
106 | template: 'Nginx main configuration file',
107 | )
108 | nginx_main_config_template.variables[:options]['stream_section'] = true
109 | end
110 |
111 | # link resource sees `@config` as its own insctance variable.
112 | link_to = @config
113 |
114 | link @symlink do
115 | action :create
116 | to link_to
117 | owner 'root'
118 | group 'root'
119 | notifies :reload, 'service[nginx]', :delayed
120 | end
121 | end
122 |
123 | action :disable do
124 | if ::File.symlink? @symlink
125 | Chef::Log.info("Disabling #{new_resource} config.")
126 |
127 | link @symlink do
128 | action :delete
129 | notifies :reload, 'service[nginx]', :delayed
130 | end
131 | end
132 | end
133 |
134 | action :delete do
135 | if ::File.exist? @config
136 | Chef::Log.info("Deleting #{new_resource} config.")
137 |
138 | action_disable
139 |
140 | file @config do
141 | action :delete
142 | end
143 | end
144 | end
145 |
--------------------------------------------------------------------------------
/templates/default/gzip.conf.erb:
--------------------------------------------------------------------------------
1 | # !!!ATTENTION!!!
2 | # This file is managed by Chef.
3 | # All manual changes will be overwritten during the next chef run.
4 | <%-
5 | types = @types || %w(
6 | text/plain
7 | text/css
8 | application/x-javascript
9 | text/xml
10 | application/xml
11 | application/xml+rss
12 | text/javascript
13 | application/json
14 | )
15 |
16 | enabled = 'off'
17 | enabled = 'on' if ( @enabled.nil? || ['on', true].include?(@enabled) )
18 | %>
19 |
20 | gzip <%= enabled %>;
21 | gzip_http_version <%= @http_version || '1.0' %>;
22 | gzip_comp_level <%= @comp_version || 4 %>;
23 | gzip_proxied <%= @proxied || 'any' %>;
24 | gzip_types <%= types.join(' ') %>;
25 | gzip_disable msie6;
26 | gzip_vary <%= @vary || 'off' %>;
--------------------------------------------------------------------------------
/templates/default/logrotate-nginx.erb:
--------------------------------------------------------------------------------
1 | # This file is generated by Chef. All changes will be discarded on next chef run.
2 | # Please, be careful.
3 |
4 | <%= @logs %> {
5 | <%= @how_often ? @how_often : "daily" %>
6 | <% if @copytruncate -%>
7 | copytruncate
8 | <% end -%>
9 | missingok
10 | notifempty
11 | rotate <%= @rotate %>
12 | compress
13 | <%- u = @user ? @user : "root" %>
14 | <%- g = @group ? @group : "adm" %>
15 | create <%= @mode %> <%= u %> <%= g %>
16 | <% if @delaycompress -%>
17 | delaycompress
18 | <% end -%>
19 | <% if @dateext -%>
20 | dateext
21 | <% end -%>
22 | <% if not @copytruncate -%>
23 | sharedscripts
24 | postrotate
25 | test -f <%= @pidfile %> && kill -USR1 "$(cat <%= @pidfile %>)"
26 | endscript
27 | <% end -%>
28 | }
29 |
--------------------------------------------------------------------------------
/templates/default/nginx.conf.erb:
--------------------------------------------------------------------------------
1 | # This file is generated and managed by Chef. It will be overwritten on the
2 | # next chef_run. Please, be careful!
3 |
4 | <% %w{daemon debug_points error_log lock_file master_process pcre_jit pid ssl_engine timer_resolution user worker_cpu_affinity worker_priority worker_processes worker_rlimit_core worker_rlimit_nofile worker_rlimit_sigpending working_directory}.each do |opt| -%>
5 | <% if @options.has_key?(opt) -%>
6 | <%= "#{opt} #{@options[opt]};" %>
7 | <% end -%>
8 | <% end -%>
9 | <% if @options.has_key?('env') -%>
10 |
11 | <% if @options['env'].is_a?(Array) -%>
12 | <% @options['env'].each do |env_var| -%>
13 | env <%= env_var %>;
14 | <% end -%>
15 | <% else -%>
16 | env <%= @options['env'] %>;
17 | <% end -%>
18 | <% end -%>
19 | <% if @options.has_key?('load_module') -%>
20 |
21 | <% if @options['load_module'].is_a?(Array) -%>
22 | <% @options['load_module'].each do |mod| -%>
23 | load_module <%= mod %>;
24 | <% end -%>
25 | <% else -%>
26 | load_module <%= @options['load_module'] %>;
27 | <% end -%>
28 | <% end -%>
29 |
30 | events {
31 | <% %w{accept_mutex accept_mutex_delay multi_accept use worker_aio_requests worker_connections}.each do |opt| -%>
32 | <% if @options.has_key?(opt) -%>
33 | <%= "#{opt} #{@options[opt]};" %>
34 | <% end -%>
35 | <% end -%>
36 | <% if @options.has_key?('debug_connection') -%>
37 |
38 | <% if @options['debug_connection'].is_a?(Array) -%>
39 | <% @options['debug_connection'].each do |connection| -%>
40 | debug_connection <%= connection %>;
41 | <% end -%>
42 | <% else -%>
43 | debug_connection <%= @options['debug_connection'] %>;
44 | <% end -%>
45 | <% end -%>
46 | }
47 |
48 | http {
49 | include <%= @options['conf_dir'] %>/mime.types;
50 | default_type application/octet-stream;
51 |
52 | log_format detailed '$remote_addr - $remote_user [$time_local] $host '
53 | '"$request" $status $body_bytes_sent '
54 | '"$http_referer" "$http_user_agent" "$http_x_forwarded_for" '
55 | '- $connection $request_time $msec '
56 | '$upstream_status $upstream_response_time';
57 |
58 | access_log <%= @options['log_dir'] %>/access.log detailed;
59 |
60 | <% %w{server_names_hash_bucket_size server_names_hash_max_size types_hash_bucket_size variables_hash_bucket_size variables_hash_max_size }.each do |opt| -%>
61 | <% if @options.has_key?(opt) -%>
62 | <%= "#{opt} #{@options[opt]};" %>
63 | <% end -%>
64 | <% end -%>
65 |
66 | include <%= @options['conf_dir'] %>/conf.d/*.conf;
67 | include <%= @options['conf_dir'] %>/sites-enabled/*;
68 | }
69 | <% if @options['stream_section'] -%>
70 |
71 | stream {
72 | include <%= @options['conf_dir'] %>/streams-enabled/*;
73 | }
74 | <% end -%>
75 | <% if ! @options['mainconfig_include'].nil? -%>
76 |
77 | include <%= @options['mainconfig_include'] %>;
78 | <% end -%>
79 |
80 |
--------------------------------------------------------------------------------
/templates/default/nxdissite.erb:
--------------------------------------------------------------------------------
1 | #!/bin/sh -e
2 |
3 | SYSCONFDIR='<%= node['nginx']['config']['conf_dir'] %>'
4 |
5 | if [ -z $1 ]; then
6 | echo "Which site would you like to disable?"
7 | echo -n "Your choices are: "
8 | ls $SYSCONFDIR/sites-enabled/* | \
9 | sed -e "s,$SYSCONFDIR/sites-enabled/,,g" | xargs echo
10 | echo -n "Site name? "
11 | read SITENAME
12 | else
13 | SITENAME=$1
14 | fi
15 |
16 | if [ $SITENAME = "default" ]; then
17 | PRIORITY="000"
18 | fi
19 |
20 | if ! [ -e $SYSCONFDIR/sites-enabled/$SITENAME -o \
21 | -e $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME" ]; then
22 | echo "This site is already disabled, or does not exist!"
23 | exit 1
24 | fi
25 |
26 | if ! rm $SYSCONFDIR/sites-enabled/$SITENAME 2>/dev/null; then
27 | rm -f $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME"
28 | fi
29 | echo "Site $SITENAME disabled; reload nginx to disable."
30 |
--------------------------------------------------------------------------------
/templates/default/nxensite.erb:
--------------------------------------------------------------------------------
1 | #!/bin/sh -e
2 |
3 | SYSCONFDIR='<%= node['nginx']['config']['conf_dir'] %>'
4 |
5 | if [ -z $1 ]; then
6 | echo "Which site would you like to enable?"
7 | echo -n "Your choices are: "
8 | ls $SYSCONFDIR/sites-available/* | \
9 | sed -e "s,$SYSCONFDIR/sites-available/,,g" | xargs echo
10 | echo -n "Site name? "
11 | read SITENAME
12 | else
13 | SITENAME=$1
14 | fi
15 |
16 | if [ $SITENAME = "default" ]; then
17 | PRIORITY="000"
18 | fi
19 |
20 | if [ -e $SYSCONFDIR/sites-enabled/$SITENAME -o \
21 | -e $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME" ]; then
22 | echo "This site is already enabled!"
23 | exit 0
24 | fi
25 |
26 | if ! [ -e $SYSCONFDIR/sites-available/$SITENAME ]; then
27 | echo "This site does not exist!"
28 | exit 1
29 | fi
30 |
31 | if [ $SITENAME = "default" ]; then
32 | ln -sf $SYSCONFDIR/sites-available/$SITENAME \
33 | $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME"
34 | else
35 | ln -sf $SYSCONFDIR/sites-available/$SITENAME $SYSCONFDIR/sites-enabled/$SITENAME
36 | fi
37 |
38 | echo "Site $SITENAME installed; reload nginx to enable."
39 |
--------------------------------------------------------------------------------
/templates/default/some-handy-defaults.conf.erb:
--------------------------------------------------------------------------------
1 | # !!!ATTENTION!!!
2 | # This file is managed by Chef.
3 | # All manual changes will be overwritten during the next chef run.
4 |
5 | <%-
6 | opts = {
7 | 'sendfile' => 'on',
8 | 'tcp_nopush' => 'on',
9 | 'tcp_nodelay' => 'on',
10 | 'server_tokens' => 'off',
11 | 'reset_timedout_connection' => 'off'
12 | }
13 |
14 | opts.each do |o,v|
15 | var = instance_variable_get("@#{o}").nil? ? opts[o] : instance_variable_get("@#{o}")
16 |
17 | var = if var == true || var == 'on'
18 | 'on'
19 | else
20 | 'off'
21 | end
22 | %>
23 | <%= "#{o} #{var};" %>
24 | <%- end %>
25 |
26 | <%- keepalive_timeout = @keepalive_timeout.nil? ? 65 : @keepalive_timeout %>
27 | <%- if keepalive_timeout %>
28 | keepalive_timeout <%= keepalive_timeout %>;
29 | <%- end %>
30 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | *#
3 | .#*
4 | \#*#
5 | .*.sw[a-z]
6 | *.un~
7 | pkg/
8 |
9 | # Berkshelf
10 | .vagrant
11 | /cookbooks
12 | Berksfile.lock
13 |
14 | # Bundler
15 | Gemfile.lock
16 | bin/*
17 | .bundle/*
18 |
19 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/Berksfile:
--------------------------------------------------------------------------------
1 | source 'https://supermarket.getchef.com'
2 |
3 | metadata
4 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 0.0.1 (2014-09-10)
2 |
3 | Initial release of nginx_test.
4 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'berkshelf'
4 |
5 | # Uncomment these lines if you want to live on the Edge:
6 | #
7 | # group :development do
8 | # gem "berkshelf", github: "berkshelf/berkshelf"
9 | # gem "vagrant", github: "mitchellh/vagrant", tag: "v1.6.3"
10 | # end
11 | #
12 | # group :plugins do
13 | # gem "vagrant-berkshelf", github: "berkshelf/vagrant-berkshelf"
14 | # gem "vagrant-omnibus", github: "schisamo/vagrant-omnibus"
15 | # end
16 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2014 YOUR_NAME
2 |
3 | All rights reserved - Do Not Redistribute
4 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/README.md:
--------------------------------------------------------------------------------
1 | # nginx_test-cookbook
2 |
3 | Test suite for cookbook[nginx]
4 |
5 | ## License and Authors
6 |
7 | Author:: Kirill Kouznetsov ()
8 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/attributes/default.rb:
--------------------------------------------------------------------------------
1 | default['nginx']['config']['server_names_hash_bucket_size'] = 64
2 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/attributes/logrotation.rb:
--------------------------------------------------------------------------------
1 | default['nginx']['logrotate']['how_often'] = 'weekly'
2 | default['nginx']['logrotate']['dateext'] = true
3 | default['nginx']['logrotate']['rotate'] = 2
4 | default['nginx']['logrotate']['mode'] = '0644'
5 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/chefignore:
--------------------------------------------------------------------------------
1 | # Put files/directories that should be ignored in this file when uploading
2 | # or sharing to the community site.
3 | # Lines that start with '# ' are comments.
4 |
5 | # OS generated files #
6 | ######################
7 | .DS_Store
8 | Icon?
9 | nohup.out
10 | ehthumbs.db
11 | Thumbs.db
12 |
13 | # SASS #
14 | ########
15 | .sass-cache
16 |
17 | # EDITORS #
18 | ###########
19 | \#*
20 | .#*
21 | *~
22 | *.sw[a-z]
23 | *.bak
24 | REVISION
25 | TAGS*
26 | tmtags
27 | *_flymake.*
28 | *_flymake
29 | *.tmproj
30 | .project
31 | .settings
32 | mkmf.log
33 |
34 | ## COMPILED ##
35 | ##############
36 | a.out
37 | *.o
38 | *.pyc
39 | *.so
40 | *.com
41 | *.class
42 | *.dll
43 | *.exe
44 | */rdoc/
45 |
46 | # Testing #
47 | ###########
48 | .watchr
49 | .rspec
50 | spec/*
51 | spec/fixtures/*
52 | test/*
53 | features/*
54 | Guardfile
55 | Procfile
56 |
57 | # SCM #
58 | #######
59 | .git
60 | */.git
61 | .gitignore
62 | .gitmodules
63 | .gitconfig
64 | .gitattributes
65 | .svn
66 | */.bzr/*
67 | */.hg/*
68 | */.svn/*
69 |
70 | # Berkshelf #
71 | #############
72 | cookbooks/*
73 | tmp
74 |
75 | # Cookbooks #
76 | #############
77 | CONTRIBUTING
78 | CHANGELOG*
79 |
80 | # Strainer #
81 | ############
82 | Colanderfile
83 | Strainerfile
84 | .colander
85 | .strainer
86 |
87 | # Vagrant #
88 | ###########
89 | .vagrant
90 | Vagrantfile
91 |
92 | # Travis #
93 | ##########
94 | .travis.yml
95 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/metadata.rb:
--------------------------------------------------------------------------------
1 | name 'nginx_test'
2 | maintainer 'Kirill Kouznetsov'
3 | maintainer_email 'agon.smith@gmail.com'
4 | license 'Apache 2.0'
5 | description 'Performs test of nginx cookbook'
6 | long_description 'Performs test of nginx cookbook'
7 | version '0.0.1'
8 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/recipes/cleaner_check.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: nginx_test
3 | # Recipe:: cleaner_check
4 | #
5 | # Copyright (C) 2015 Kirill Kouznetsov
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | # rubocop:disable Layout/IndentHeredoc
21 | # rubocop:disable Naming/HeredocDelimiterNaming
22 | file '/etc/nginx/sites-available/20-hahaha.conf' do
23 | owner 'root'
24 | group 'root'
25 | mode '0644'
26 | content <<-EOF
27 | # This file should be absent!!!
28 |
29 | server {
30 | listen 0.0.0.0:8080;
31 | server_name _;
32 | root /var/www/;
33 | index index.html;
34 | charset utf-8;
35 | }
36 | EOF
37 | end
38 |
39 | link '/etc/nginx/sites-enabled/20-hahaha.conf' do
40 | to '/etc/nginx/sites-available/20-hahaha.conf'
41 | end
42 |
43 | file '/etc/nginx/streams-enabled/wanked.conf' do
44 | owner 'root'
45 | group 'root'
46 | mode '0644'
47 | content <<-EOF
48 | # Your system has been officially WANKed!!!.
49 | EOF
50 | end
51 | # rubocop:enable Layout/IndentHeredoc
52 | # rubocop:enable Naming/HeredocDelimiterNaming
53 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: nginx_test
3 | # Recipe:: default
4 | #
5 | # Copyright (C) 2015 Kirill Kouznetsov
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | file 'nginx_site_notification' do
21 | path '/tmp/nginx_site_notification.txt'
22 | content 'passed'
23 | action :nothing
24 | end
25 |
26 | nginx_site 'frontend' do
27 | notifies :create, 'file[nginx_site_notification]'
28 | end
29 |
30 | template '/etc/nginx/mainconfig_custom_include.conf' do
31 | owner 'root'
32 | group 'root'
33 | mode '0644'
34 | source 'test01.conf.erb'
35 | end
36 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/recipes/helper_templates.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: nginx_test
3 | # Recipe:: helper_templates
4 | #
5 | # Copyright (C) 2014 Kirill Kouznetsov
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | nginx_site '00-gzip-defaults' do
21 | cookbook 'nginx_lwrp'
22 | template 'gzip.conf.erb'
23 | end
24 |
25 | template '/tmp/01-some-handy-defaults' do
26 | cookbook 'nginx_lwrp'
27 | source 'some-handy-defaults.conf.erb'
28 | variables(
29 | sendfile: false,
30 | tcp_nopush: 'on',
31 | tcp_nodelay: true,
32 | server_tokens: 'off',
33 | keepalive_timeout: false,
34 | )
35 | end
36 |
37 | template '/tmp/02-some-handy-defaults' do
38 | cookbook 'nginx_lwrp'
39 | source 'some-handy-defaults.conf.erb'
40 | variables(
41 | server_tokens: 'on',
42 | reset_timedout_connection: true,
43 | )
44 | end
45 |
46 | template '/tmp/03-some-handy-defaults' do
47 | cookbook 'nginx_lwrp'
48 | source 'some-handy-defaults.conf.erb'
49 | end
50 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/recipes/streams.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: nginx_test
3 | # Recipe:: stream
4 | #
5 | # Copyright (C) 2015 Kirill Kouznetsov
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | nginx_site 'test01'
21 | nginx_stream 'test01'
22 |
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/templates/default/frontend.conf.erb:
--------------------------------------------------------------------------------
1 | # This is a test configuration for nginx cookbook.
2 | # Be warned - Managed by Chef!!!
3 |
4 | server {
5 | listen 127.0.0.1:80 default;
6 | server_name _;
7 | root /var/www/;
8 | index index.html;
9 | charset utf-8;
10 |
11 | access_log <%= node['nginx']['config']['log_dir'] %>/frontend.access.log detailed;
12 | error_log <%= node['nginx']['config']['log_dir'] %>/frontend.error.log;
13 |
14 | location /nya {
15 | add_header Neko nya;
16 | return 204;
17 | }
18 | }
--------------------------------------------------------------------------------
/test/cookbooks/nginx_test/templates/default/test01.conf.erb:
--------------------------------------------------------------------------------
1 | # This test config was generated by chef
2 | # It is empty but who cares. We test the recipe, not a nginx code.
3 |
4 | # So... Here you are a cat, maybe:
5 |
6 | # (( /|_/|
7 | # \\.._.' , ,\
8 | # /\ | '.__ v /
9 | # (_ . / "
10 | # ) _)._ _ /
11 | # '.\ \|( / ( mrf
12 | # '' ''\\ \\
13 |
14 | # Everybody likes them somehow. I don't. But if it makes you happier...
--------------------------------------------------------------------------------
/test/integration/default/inspec/helper_templates_spec.rb:
--------------------------------------------------------------------------------
1 | control 'helper templates' do
2 | title 'Checking helper nginx templates.'
3 |
4 | describe file('/etc/nginx/sites-available/00-gzip-defaults.conf') do
5 | it { should be_file }
6 | it { should be_readable }
7 | it { should be_owned_by 'root' }
8 | its('content') { should match(/gzip on;/) }
9 | its('content') { should match(/gzip_http_version 1.0;/) }
10 | its('content') { should match(/gzip_comp_level 4;/) }
11 | its('content') { should match(/gzip_proxied any;/) }
12 | its('content') { should match(%r{gzip_types text/plain text/css}) }
13 | its('content') { should match(/gzip_disable msie6;/) }
14 | its('content') { should match(/gzip_vary off;/) }
15 | end
16 |
17 | describe file('/tmp/01-some-handy-defaults') do
18 | it { should be_file }
19 | it { should be_readable }
20 | it { should be_owned_by 'root' }
21 | its('content') { should match(/This file is managed by Chef/) }
22 | its('content') { should match(/sendfile off;/) }
23 | its('content') { should match(/tcp_nopush on;/) }
24 | its('content') { should match(/tcp_nodelay on;/) }
25 | its('content') { should match(/server_tokens off;/) }
26 | its('content') { should match(/reset_timedout_connection off;/) }
27 | its('content') { should_not match(/keepalive_timeout/) }
28 | end
29 |
30 | describe file('/tmp/02-some-handy-defaults') do
31 | it { should be_file }
32 | it { should be_readable }
33 | it { should be_owned_by 'root' }
34 | its('content') { should match(/This file is managed by Chef/) }
35 | its('content') { should match(/sendfile on;/) }
36 | its('content') { should match(/tcp_nopush on;/) }
37 | its('content') { should match(/tcp_nodelay on;/) }
38 | its('content') { should match(/server_tokens on;/) }
39 | its('content') { should match(/reset_timedout_connection on;/) }
40 | its('content') { should match(/keepalive_timeout 65;/) }
41 | end
42 |
43 | describe file('/tmp/03-some-handy-defaults') do
44 | it { should be_file }
45 | it { should be_readable }
46 | it { should be_owned_by 'root' }
47 | its('content') { should match(/This file is managed by Chef/) }
48 | its('content') { should match(/sendfile on;/) }
49 | its('content') { should match(/tcp_nopush on;/) }
50 | its('content') { should match(/tcp_nodelay on;/) }
51 | its('content') { should match(/server_tokens off;/) }
52 | its('content') { should match(/reset_timedout_connection off;/) }
53 | its('content') { should match(/keepalive_timeout 65;/) }
54 | end
55 | end
56 |
--------------------------------------------------------------------------------
/test/integration/default/inspec/logrotation_spec.rb:
--------------------------------------------------------------------------------
1 | control 'nginx log rotation' do
2 | title 'Checking nginx log rotation settings'
3 |
4 | describe file('/etc/logrotate.d/nginx') do
5 | it { should be_file }
6 | it { should be_readable }
7 | it { should be_owned_by 'root' }
8 | its('content') { should match(%r{/var/log/nginx/\*\.log}) }
9 | its('content') { should match(/weekly/) }
10 | its('content') { should match(/rotate 2/) }
11 | its('content') { should match(/dateext/) }
12 | its('content') { should match(/create 0644 root adm/) }
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/test/integration/default/inspec/nginx_spec.rb:
--------------------------------------------------------------------------------
1 | control 'nginx configuration tests' do
2 | title 'Checking nginx custom configuration'
3 |
4 | describe port('127.0.0.1', 80) do
5 | it { should be_listening }
6 | end
7 |
8 | describe file('/etc/nginx/mainconfig_custom_include.conf') do
9 | it { should be_file }
10 | it { should be_readable }
11 | it { should be_owned_by 'root' }
12 | end
13 |
14 | describe file('/etc/nginx/nginx.conf') do
15 | its('content') do
16 | should match(%r{^include /etc/nginx/mainconfig_custom_include\.conf;$})
17 | end
18 | end
19 |
20 | describe file('/etc/nginx/sites-available/frontend.conf') do
21 | it { should be_file }
22 | it { should be_readable }
23 | it { should be_owned_by 'root' }
24 | end
25 |
26 | describe file('/etc/nginx/sites-enabled/frontend.conf') do
27 | it { should be_symlink }
28 | it { should be_readable }
29 | it { should be_owned_by 'root' }
30 | end
31 |
32 | describe http('http://localhost/nya', enable_remote_worker: true) do
33 | its('status') { should cmp 204 }
34 | its('headers.Neko') { should cmp 'nya' }
35 | end
36 |
37 | # Test for 'nginx_mainconfig'
38 | describe file('/etc/nginx/nginx.conf') do
39 | its('content') do
40 | should match(/^[ \t]*server_names_hash_bucket_size[ \t]+64;$/)
41 | end
42 | end
43 |
44 | describe file('/tmp/nginx_site_notification.txt') do
45 | it { should be_file }
46 | it { should be_readable }
47 | its('content') { should match(/passed/) }
48 | end
49 |
50 | # dhparam file generation
51 | describe file('/etc/nginx/dhparam.pem') do
52 | it { should be_readable }
53 | it { should be_owned_by 'root' }
54 | end
55 | end
56 |
--------------------------------------------------------------------------------
/test/integration/default/inspec/official_repo_spec.rb:
--------------------------------------------------------------------------------
1 | control 'nginx package repo' do
2 | title 'Checking that nginx is installed from the official repo'
3 |
4 | os_codename = command('/usr/bin/lsb_release -cs').stdout.strip.downcase
5 | repo_url = "http://nginx.org/packages/mainline/#{os[:name]}/"
6 |
7 | describe file('/etc/apt/sources.list.d/nginx.list') do
8 | it { should be_file }
9 | it { should be_readable }
10 | it { should be_owned_by 'root' }
11 |
12 | its('content') do
13 | should match(/deb[ \t]+"#{repo_url}"[ \t]+#{os_codename}[ \t]+nginx/)
14 | end
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/test/integration/default/inspec/shared_spec.rb:
--------------------------------------------------------------------------------
1 | control 'basic nginx tests' do
2 | title 'Check basic nginx installation'
3 |
4 | describe package('nginx') do
5 | it { should be_installed }
6 | end
7 |
8 | # Chef 14 resource service is broken on a first run on Ubuntu 14.
9 | if os.name == 'ubuntu' and os.release.to_f > 14.04
10 | describe service('nginx') do
11 | it { should be_enabled }
12 | it { should be_running }
13 | end
14 | end
15 |
16 | describe file('/etc/nginx/nginx.conf') do
17 | it { should be_file }
18 | it { should be_readable }
19 | it { should be_owned_by 'root' }
20 |
21 | its('content') { should match(/This file is generated and managed by/) }
22 | its('content') { should match(/'- \$connection/) }
23 |
24 | its('content') do
25 | should match(%r{^[ \t]*include[ \t]+/etc/nginx/mime.types;$})
26 | end
27 | end
28 |
29 | describe file('/etc/nginx/mime.types') do
30 | it { should be_file }
31 | it { should be_readable }
32 | it { should be_owned_by 'root' }
33 | its('content') { should match(/woff2/) }
34 | end
35 |
36 | describe command('/usr/sbin/nginx -tq') do
37 | its('exit_status') { should eq 0 }
38 | end
39 | end
40 |
--------------------------------------------------------------------------------
/test/integration/default/inspec/streams_spec.rb:
--------------------------------------------------------------------------------
1 | control 'nginx streams configuration' do
2 | title 'Check custom configuration for Nginx streams.'
3 |
4 | %w[sites streams].each do |section|
5 | describe file("/etc/nginx/#{section}-available/test01.conf") do
6 | it { should be_file }
7 | it { should be_readable }
8 | it { should be_owned_by 'root' }
9 | end
10 |
11 | describe file("/etc/nginx/#{section}-enabled/test01.conf") do
12 | it { should be_symlink }
13 | it { should be_readable }
14 | it { should be_owned_by 'root' }
15 | end
16 |
17 | describe file("/etc/nginx/#{section}-available/test01.conf") do
18 | its('content') { should match(/Here you are a cat/) }
19 | end
20 | end
21 |
22 | # Test for 'nginx_mainconfig'
23 | describe file('/etc/nginx/nginx.conf') do
24 | its('content') { should match(/^[ \t]*stream {$/) }
25 | end
26 | end
27 |
--------------------------------------------------------------------------------