Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

More complex site configuration not possible with template #131

Closed
surfer190 opened this issue Nov 9, 2016 · 6 comments
Closed

More complex site configuration not possible with template #131

surfer190 opened this issue Nov 9, 2016 · 6 comments

Comments

@surfer190
Copy link

surfer190 commented Nov 9, 2016

Based on the template site.conf.j2, you can only configure things inside the a server block.
So that prevents more advanced configurations like the below.

map $http_x_forwarded_proto $fastcgi_https {
    default $https;
    https on;
}

server {
   listen 8080;
   listen [::]:8080;

   server_name "{{ server_name }}";
   access_log /var/log/nginx/{{ site_name }}-access.log;
   error_log /var/log/nginx/{{ site_name }}-error.log;
   include {{ doc_root }}/nginx.conf;
   set $MAGE_ROOT "{{ doc_root }}";
}

upstream fastcgi_backend {
   server unix:/var/run/php/php7.0-fpm.sock;
}

server {
    listen 443;
    listen [::]:443;
    ssl on;

    ssl_certificate {{ ssl_certificate }};
    ssl_certificate_key {{ ssl_key }};
    ssl_protocols        TLSv1.1 TLSv1.2;

    # Other ssl_* server context directives...
    access_log /var/log/nginx/ssl-{{ site_name }}-access.log;
    error_log /var/log/nginx/ssl-{{ site_name }}-error.log;

    # Proxy
    location / {
        proxy_pass http://127.0.0.1:80;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Port 443;
        proxy_set_header Host $host;
    }
}
@jdauphant
Copy link
Owner

You have to the variable "nginx_configs", like that:

nginx_configs:
         default_https:
            - map $http_x_forwarded_proto $fastcgi_https {
                 default $https;
                  https on;
              }
         php_upstream:
            - upstream fastcgi_backend {
                   server unix:/var/run/php/php7.0-fpm.sock;
              }

It's what you want to do ?

@realmyst
Copy link
Contributor

By the way, what about configs outside http block? E.g. including dynamic modules. We can't do this now. So we need a static config line include /etc/nginx/modules-enabled/*.conf; or a possibility to add custom configs outside http config block

@jdauphant
Copy link
Owner

You can use ansible templating for that.
You have an example here:
https://github.com/jdauphant/ansible-role-nginx/releases/tag/v1.2

It's a recurring question, if someone have time to improve the doc, a PR will be more than welcome.

@realmyst
Copy link
Contributor

No, I can't. Actually, my problem not linked with this issue
I talk about configuration at main context (on the same level with user, worker_processes, pid, etc). I make a PR with solving this problem #132

@jdauphant
Copy link
Owner

@realmyst Ok, my mistake.

@surfer190 Have you solved your issue ?

@surfer190
Copy link
Author

@jdauphant Yes, that will work for a dedicated single site server. But may be an issue if you host multiple sites and want per site configs. Nonetheless, I am happy, thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants