Skip to content

Commit

Permalink
Merge pull request #20 from punktDe/override-mimetypes
Browse files Browse the repository at this point in the history
FEATURE: add option to extend/override mimetypes
  • Loading branch information
medanthelinium authored Jul 16, 2024
2 parents f6baddf + 028570a commit 26235ba
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.pyc
__pycache__
.fact_cache
.idea
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,27 @@ This snippet is stored in a dedicated file `/etc/nginx/include/security_txt.conf
include /etc/nginx/include/security_txt.conf;
```
If set, serves a [RFC9116](https://www.rfc-editor.org/info/rfc9116) information under /security.txt and /.well-known/security.txt

### mimetypes

You can override or add new mimetypes to nginx.
key must be the mimetype, value is a list of values which are combined with spaces.
If a mimetype is already present it gets **replaced**.

```yaml
nginx:
mimetypes:
font-woff2:
key: "application/font-woff2"
value:
- woff2
```

The previous example generates this line within ./nginx/mime.types
```
types {
...
application/font-woff2 woff2;
...
}
```
1 change: 1 addition & 0 deletions defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ nginx:
Policy:
Hiring:
CSAF:
mimetypes:
4 changes: 4 additions & 0 deletions tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@
when:
- nginx.modsecurity.enabled
- modsecurity_module.stat.exists

- name: Modify mimetypes
ansible.builtin.include_tasks: mimetypes.yaml
when: nginx.mimetypes is not string and nginx.mimetypes is iterable and nginx.mimetypes is mapping
10 changes: 10 additions & 0 deletions tasks/mimetypes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: Override mimetypes
ansible.builtin.lineinfile:
path: "{{ nginx.prefix.config }}/mime.types"
line: "{{ item.value.key }} {{ item.value.value | join(' ') }};"
search_string: '{{ item.value.key }}'
state: present
insertbefore: "}"

loop: "{{ nginx.mimetypes | dict2items }}"
when: item.value.key is defined and item.value.key | length > 0 and item.value.value is defined

0 comments on commit 26235ba

Please sign in to comment.