Skip to content

Commit 19f06c4

Browse files
committed
[DOC] Updated.
Signed-off-by: ecaepp <peace.patrick51@gmail.com>
1 parent 63e4606 commit 19f06c4

File tree

1 file changed

+126
-62
lines changed

1 file changed

+126
-62
lines changed

README.md

Lines changed: 126 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,45 @@ This role is currently in alpha testing
1010

1111
Ansible 2.4
1212

13-
## Role Variables
13+
-------
1414

15-
Base role variables are defined in `default/main.yml` and is divied in to blocks base on the conf file or vhost configureation.
15+
## Configuration
1616

17-
The Role Options section is for configureing option for how the role function and which task to run.
17+
All options in this section are configured as defaults for Nginx and are defined in `defaults.yml` so that they can easly be overwritten within the playbook.
18+
19+
### Self Signed Cert Generation
20+
21+
The Role has an option for generating a self signed TLS cert for testing. This setting is set to false defaultly to prevent unwanted self signed cert generation.
1822

1923
```yaml
2024
selfsigned_cert: false # Generate self signed SSL cert.
2125
```
2226
23-
The role creates three config file at the moment `nginx.conf, general.conf, and a vhost conf`.
27+
### Configuratoin Files
28+
29+
All options in this section are configured as defaults for Nginx and are defind in `defaults.yml` so that they can easly be overwritten within the playbook.
30+
31+
This role currently creates three conf files.
2432

25-
Configs are defined in `defaults/main.yml so they can be easily overwritten elsewhere in the playbook.
33+
* nginx.conf
34+
* general.conf
35+
* server.conf (vhost)
2636

27-
Example of modifing Nginx configureation:
37+
#### nginx.conf
2838

29-
Lets take a look at the smaple configs found in `defaults/main.yml` that are found in the `nginx.conf` section.
39+
This file contains options for cofiguring global options pretaining to the Nginx service.
3040

3141
```yaml
42+
# Service
43+
nginx_user: www-data
44+
worker_processes: auto
45+
nginx_pid_file: /var/run/nginx.pid
46+
worker_rlimit_nofile: 8192
47+
48+
# Events
49+
event_multi_accept: "on"
50+
worker_connections: 4096
51+
3252
# http
3353
charset: utf-8
3454
sendfile: "on"
@@ -37,67 +57,111 @@ tcp_nodelay: "on"
3757
types_hash_max_size: 2048
3858
client_max_body_size: 16M
3959
server_tokens: "off"
60+
61+
# MIME
62+
include: mime.types
63+
default_type: application/octet-stream
64+
65+
# Logging
66+
access_log: /var/log/nginx/access.log
67+
error_log: /var/log/nginx/error.log warn
68+
69+
# Limits
70+
limit_req_log_level: warn
71+
limit_req_zone: $binary_remote_addr zone=login:10m rate=10r/m
72+
73+
# SSL
74+
ssl_session_timeout: 1d
75+
ssl_session_cache: shared:SSL:50m
76+
ssl_session_tickets: "off"
77+
78+
# Modern Config
79+
ssl_protocols: TLSv1.2
80+
ssl_ciphers: ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
81+
ssl_prefer_server_ciphers: "on"
82+
83+
# OSCP Stapling
84+
stapling: "on"
85+
stapling_verify: "on"
86+
resolver: 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=60s
87+
resolver_timeout: 2s
88+
89+
# Load Configs
90+
conf_files: /etc/nginx/conf.d/*.conf
91+
sites_enabled: /etc/nginx/sites-enabled/*
4092
```
4193

42-
The recommended way to change default value of varibles for `nginx.conf` and `general.conf` is to copy the vars that need to be changed to `vars/main.yml`. It is best to also leave a comment noting the conf file the variable relates to and which stanza the config is stored in. This allows for easy versioning of custom vars in you own repo.
94+
#### general.conf
4395

44-
```yaml
45-
# nginx.conf
96+
This conf file is used to set security headers, restrict access to `.` files, and compression options.
4697

47-
# http
48-
types_hash_max_size: 1024
49-
server_tokens: "on"
98+
```yaml
99+
# Security Headers
100+
header_options: |
101+
add_header X-Frame-Options "SAMEORIGIN" always;
102+
add_header X-XSS-Protection "1; mode=block" always;
103+
add_header X-Content-Type-Options "nosniff" always;
104+
add_header Referrer-Policy "no-referrer-when-downgrade" always;
105+
add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
106+
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
107+
# . files
108+
dot_file_location: "deny all"
109+
110+
# Assets media
111+
media_expires: 7d
112+
media_access_log: "off"
113+
114+
# svg, fonts
115+
fonts_headrer_options: 'Access-Control-Allow-Origin "*"'
116+
fonts_expire: 78
117+
fonts_access_log: "off"
118+
119+
# Gzip
120+
gzip_status: "on"
121+
gzip_vary: "on"
122+
gzip_proxied: any
123+
gzip_comp_level: 6
124+
gzip_types: 'text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml'
50125
```
51126

52-
```text
53-
Note: Configuring variable like this allows for easy versioning of custom vars in your own repo/vc system.
54-
```
127+
`**NOTE:** This file is likely to be deprecated in future when I have time to rewrite the conf file tasks.`
55128

56-
## VHosts
129+
#### server.conf
57130

58-
This role uses the template `templates/server.conf.j2` to create virtualhost conf files for applications.
131+
This file is used to configure Nginx to actually server the web application. This role generates these files from a template in the task `tasks/configure.yml`.
59132

60-
First create a new `.yml` file in `vars` named after the application ex. `someapp.yml`
61-
Second copy the vars from the vhosts section in `defaults/main.yml` the file you created and then fill in the vars to configure the vhost.
62-
Any config not need can be remove. ex. The `fastcgi_php` configs can be deleted if they are not need as long proper YAML indentaion is maintained.
133+
Currently the options below are required for Nginx to be able to run the app
63134

64-
Example vhosts file for some app:
135+
* server_name
136+
* listen_port
137+
* root_dir
138+
* index_name
65139

66140
```yaml
67-
vhost:
68-
- server_name: someapp.com
141+
vhost: []
142+
- server_name: test.com
69143
listen_port: 80
70-
root_dir: /var/www/someapp
144+
root_dir: /var/www
71145
index_name: index.html
72146
73-
# ssl:
74-
# cert_dir: /etc/nginx/ssl
75-
# crt: '/etc/nginx/ssl/server.crt'
76-
# key: '/etc/nginx/ssl/server.key'
147+
ssl:
148+
cert_dir: /etc/nginx/ssl
149+
crt: '/etc/nginx/ssl/server.crt'
150+
key: '/etc/nginx/ssl/server.key'
77151
78-
# security_headers:
79-
# transport_security: Strict-Transport-Security "max-age=15768000; includeSubdomains",
80-
# xframe_options: X-Frame-Options SAMEORIGIN
152+
security_headers:
153+
transport_security: Strict-Transport-Security "max-age=15768000; includeSubdomains",
154+
xframe_options: X-Frame-Options SAMEORIGIN
81155
82-
try_files: '$uri $uri/ /index.html'
156+
try_files: '$uri $uri/'
83157
84-
# fastcgi_php:
85-
# fastcgi_split_path_info: fastcgi_split_path_info ^(.+\.php)(/.+)$
86-
# fastcgi_pass: 'fastcgi_pass unix:/var/run/php7.0-fpm.sock'
87-
# fastcgi_index: fastcgi_index index.php,
88-
# include_fastcgi: include fastcgi.conf
158+
fastcgi_php:
159+
fastcgi_split_path_info: fastcgi_split_path_info ^(.+\.php)(/.+)$
160+
fastcgi_pass: 'fastcgi_pass unix:/var/run/php7.0-fpm.sock'
161+
fastcgi_index: fastcgi_index index.php,
162+
include_fastcgi: include fastcgi.conf
89163
```
90164

91-
The SSL configs can be uncommented and set to the location of any certificates that have been uploaded or generated for the application to enable HTTPS.
92-
93-
The `security_headers` are set globally in `general.conf` and can be modified here.
94-
95-
`Fastcgi_php` can be uncommented for php apps that utilize fastcgi. Please note that this role currently only supports `php7.0-fpm`.
96-
97-
## Dependencies
98-
99-
Currently there are no plans for this role to have any dependencies of other roles.
100-
101165
## Example Playbook
102166

103167
Including an example of how to use your role (for instance, with variables
@@ -109,24 +173,24 @@ passed in as parameters) is always nice for users too:
109173
roles:
110174
- { role: ecaepp.nginx }
111175

112-
vars/someapp.yml
176+
vars/someapp.yml
113177

114-
vhost:
115-
- server_name: test.com
116-
listen_port: 80
117-
root_dir: /var/www/someapp/app/webroot/
118-
index_name: index.html
178+
vhost:
179+
- server_name: test.com
180+
listen_port: 80
181+
root_dir: /var/www/someapp/app/webroot/
182+
index_name: index.html
119183

120-
ssl:
121-
cert_dir: /etc/nginx/ssl
122-
crt: '/etc/nginx/ssl/someapp.com.crt'
123-
key: '/etc/nginx/ssl/someapp.com.key'
184+
ssl:
185+
cert_dir: /etc/nginx/ssl
186+
crt: '/etc/nginx/ssl/someapp.com.crt'
187+
key: '/etc/nginx/ssl/someapp.com.key'
124188

125-
security_headers:
126-
transport_security: Strict-Transport-Security "max-age=15768000; includeSubdomains",
127-
xframe_options: X-Frame-Options SAMEORIGIN
189+
security_headers:
190+
transport_security: Strict-Transport-Security "max-age=15768000; includeSubdomains",
191+
xframe_options: X-Frame-Options SAMEORIGIN
128192

129-
try_files: '$uri $uri/ /index.html'
193+
try_files: '$uri $uri/ /index.html'
130194

131195
## License
132196

0 commit comments

Comments
 (0)