jdauphant / ansible-role-nginx

Ansible role to install and manage nginx configuration
655 stars 302 forks source link

Rogue character in my config #154

Closed josephbisaillon closed 6 years ago

josephbisaillon commented 7 years ago

Not sure if this there is something wrong with my script or something wrong with the generation. But I'm hoping someone can help me figure out where a rogue ';' is coming from.


- hosts: all
  roles:
    - role: jdauphant.nginx
      nginx_http_params:
        - sendfile on
        - access_log /var/log/nginx/access.log
        - |
          map $http_upgrade $connection_upgrade {
            default update;
             '' close;
          }
      # The user to run nginx
      nginx_user: "www-data"

      # A list of hashs that define the servers for nginx,
      # as with http parameters. Any valid server parameters
      # can be defined here.
      nginx_sites:
        default:
          - listen 80
          - listen [::]:80 default_server ipv6only=on
          - listen 443 ssl
          - server_name localhost
          - root "/usr/share/nginx/html"
          - index index.html index.htm
          - |
            location /node/ {
              proxy_pass http://127.0.0.1:9000;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection $connection_upgrade;
            }
          - location / { try_files $uri $uri/ =404; }

Here is the generated nginx.conf

#Ansible managed
user              www-data  www-data;

worker_processes  2;

pid        /var/run/nginx.pid;

worker_rlimit_nofile 1024;

events {
        worker_connections 512;
}

http {

        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        sendfile on;
        access_log /var/log/nginx/access.log;
        map $http_upgrade $connection_upgrade {
  default update;
   '' close;
}
; <------ ROGUE CHARACTER

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}
jdauphant commented 7 years ago

"- |" and {} isn't managed in nginx_http_params :(

It will work if you place map {} inside nginx_configs :

nginx_configs:
  upgrade:
       - map $http_upgrade $connection_upgrade {
            default update;
             '' close;
          }

We may need to simplify, we can have some confusion if we need to use nginx_http_params or nginx_configs.

josephbisaillon commented 7 years ago

Ah, and it gets added to/conf.d/upgrade.conf I think that works. Thanks!

wvidana commented 7 years ago

Here some solution to this issue. Not sure if within the global design of this role, but this fix works on our setup, where we also wanted a map {} block on our http params. https://github.com/jdauphant/ansible-role-nginx/pull/183