ansible-role-nginx-config
ansible-role-nginx-config copied to clipboard
how to insert an if statement in the server stanza
how would I insert an if statement such as:
if ($request_method = POST) {
return 405;
}
in the server stanza? Thanks!
You would use the custom_directives parameter like it's used in https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/default/converge.yml#L702 but in the server block instead.
many thanks! based on your tip, I fixed my issue with this code:
- template_file: http/default.conf.j2
deployment_location: /etc/nginx/sites-available/xxxxxxx
config:
servers:
- core:
...
ssl:
...
locations:
- location: /
...
custom_directives:
- if ( $host !~* ^yyyyyy.example.com$ ) { return 444; }
you can close this issue from my part ...
NOTE: the remark here that "You need to add a semi-colon at the end of each directive" is misleading; in this case the strimg must end with }
Point taken, I will make a small edit to the docs and close this issue once that is done 😄