nginxinc / ansible-role-nginx-config

Ansible role for configuring NGINX
https://galaxy.ansible.com/nginxinc/nginx_config
Apache License 2.0
161 stars 73 forks source link

Nested location #347

Open GaetanJourdan opened 1 year ago

GaetanJourdan commented 1 year ago

Hello! I have the impression that it is not possible to have a nested location directive within a location directive. Is this a planned feature? Thanks :)

alessfg commented 1 year ago

It's not planned at this time. That being said, you should be able to define some by using the custom_directives parameter https://github.com/nginxinc/ansible-role-nginx-config/blob/main/templates/http/default.conf.j2#L427-L435 😄

gimli2 commented 5 months ago

It would be nice to be able to combine things like authentication and php. The proposed way with custon_directives is working but definitely it is ugly hackish approach ;-)

...
- location: ~ /foto/
  auth_basic:
    realm: "'Please log in.'"
    user_file: $document_root/foto/.htpasswd
  custom_directives:
    - "location ~ \\.php {"
    - "    include snippets/fastcgi-php.conf;"
    - "    fastcgi_pass unix:/run/php/php-fpm.sock;"
    - "}"