1

I am stuck with the following nginx conf template:

# Special characters - dollar signs, spaces inside of quotes, etc. -
# should be escaped with a single backslash or can cause deploy failures.

server {
    listen      [::]:80;
    listen      80;
    server_name $NOSSL_SERVER_NAME;
    access_log  /var/log/nginx/${APP}-access.log;
    error_log   /var/log/nginx/${APP}-error.log;

    # set a custom header for requests
    # add_header X-Served-By www-ec2-01;

    location    / {
      proxy_pass  http://$APP;
      proxy_http_version 1.1;
      proxy_set_header Upgrade \$http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host \$http_host;
      proxy_set_header X-Forwarded-Proto \$scheme;
      proxy_set_header X-Forwarded-For \$remote_addr;
      proxy_set_header X-Forwarded-Port \$server_port;
      proxy_set_header X-Request-Start \$msec;
    }

    include $DOKKU_ROOT/$APP/nginx.conf.d/*.conf;

    # Proxy download 
    location ~* ^/internal_redirect/(.*?)/(.*) {
    # Do not allow people to mess with this location directly
    # Only internal redirects are allowed
    internal;

    # Location-specific logging
    access_log logs/internal_redirect.access.log main;
    error_log logs/internal_redirect.error.log warn;

    # Extract download url from the request
    set $download_uri \$2;
    set $download_host \$1;

    # Compose download url
    set $download_url http://\$download_host/\$download_uri;

    # Set download request headers
    proxy_set_header Host \$download_host;
    proxy_set_header Authorization '';

    # The next two lines could be used if your storage 
    # backend does not support Content-Disposition 
    # headers used to specify file name browsers use 
    # when save content to the disk
    proxy_hide_header Content-Disposition;
    add_header Content-Disposition 'attachment; filename="\$args"';

    # Do not touch local disks when proxying 
    # content to clients
    proxy_max_temp_file_size 0;

    # Download the file and send it to client
    proxy_pass \$download_url;
  }
}

The dokku docs tell me to escape '$' with a single \, so I did that.

Can a nginx wiz tell a nginx n00b what is wrong with the above template?

Dokku outputs the following error:

remote: nginx: [emerg] unknown log format "main" in /home/dokku/everseller/nginx.conf:117
remote: nginx: configuration file /etc/nginx/nginx.conf test failed

Thanks!

==== updated conf ====

# Special characters - dollar signs, spaces inside of quotes, etc. -
# should be escaped with a single backslash or can cause deploy failures.

server {
  listen      [::]:80;
  listen      80;
  server_name $NOSSL_SERVER_NAME;
  access_log  /var/log/nginx/${APP}-access.log;
  error_log   /var/log/nginx/${APP}-error.log;

  # set a custom header for requests
  # add_header X-Served-By www-ec2-01;

  location    / {
    proxy_pass  http://$APP;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Port $server_port;
    proxy_set_header X-Request-Start $msec;
  }

  include $DOKKU_ROOT/$APP/nginx.conf.d/*.conf;

  # Proxy download 
  location ~* ^/internal_redirect/(.*?)/(.*) {
  # Do not allow people to mess with this location directly
  # Only internal redirects are allowed
  internal;

  # Location-specific logging
  access_log logs/internal_redirect.access.log main;
  error_log logs/internal_redirect.error.log warn;

  # Extract download url from the request
  set $download_uri $2;
  set $download_host $1;

  # Compose download url
  set $download_url http://$download_host/$download_uri;

  # Set download request headers
  proxy_set_header Host $download_host;
  proxy_set_header Authorization '';

  # The next two lines could be used if your storage 
  # backend does not support Content-Disposition 
  # headers used to specify file name browsers use 
  # when save content to the disk
  proxy_hide_header Content-Disposition;
  add_header Content-Disposition 'attachment; filename="$args"';

  # Do not touch local disks when proxying 
  # content to clients
  proxy_max_temp_file_size 0;

  # Download the file and send it to client
  proxy_pass $download_url;
    }
}
0

Dollar signs indicate variables. So if used somewhere not indicating a variable they should be escaped.

Your config contains a lot of variables, where the dollar signs should not be escaped, e.g. proxy_set_header Upgrade \$http_upgrade;
should be
proxy_set_header Upgrade $http_upgrade;

proxy_set_header Host \$http_host; should read proxy_set_header Host $http_host; and so forth.

By the way: I'm not a wiz ;-)

  • Thanks :-). Got a new error now. [emerg] invalid number of arguments in "proxy_set_header" directive in /home/dokku/everseller/nginx.conf:99. Again, what's a n00b to do? :-) I have edited my original question with the updated conf. – Corstiaan Apr 21 '16 at 14:34
  • Well, I dont't know anything about dokku, but g00gle gives me this: github.com/dokku/dokku/issues/1059 So you could try to comment out (# at the beginning of the line) "proxy_set_header ..." – JosefScript Apr 21 '16 at 15:37
  • I wasn't escaping special characters properly. Thanks! – Corstiaan Apr 22 '16 at 7:01
  • So, does it work now? Answer accepted? --> 'Click' :) – JosefScript Apr 22 '16 at 7:51
  • Well, the backslashes need to be present after all since it was a template that was being parsed. You put me on the right track but technically your answer is not the right one. – Corstiaan Apr 22 '16 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.