【问题标题】:Nginx conf template not working with dokkuNginx conf 模板不适用于 dokku
【发布时间】:2016-04-21 13:31:08
【问题描述】:

我坚持使用以下 nginx 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;
  }
}

dokku 文档告诉我用一个 \ 转义“$”,所以我这样做了。

nginx wiz 能否告诉 nginx n00b 上面的模板有什么问题?

Dokku 输出如下错误:

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

谢谢!

【问题讨论】:

    标签: nginx docker dokku


    【解决方案1】:

    行:

    access_log logs/internal_redirect.access.log main;
    

    假设有一个log_format 指令指定main 格式。默认情况下,nginx 提供 combined 格式。

    将上面的行替换为:

    access_log logs/internal_redirect.access.log combined;
    

    或者定义一个log_format main

    详情请见this document

    【讨论】:

    • 谢谢!进行了编辑。现在我有一个不同的错误:[emerg] /home/dokku/everseller/nginx.conf:117 中的“set”指令中的参数数量无效。什么是n00b? :-)
    • @Corstiaan 你的$ 指令中有一些未转义的set
    • 我们正在取得进展:-)。但是,不,我收到此错误:[emerg] /home/dokku/everseller/nginx.conf:96 中“proxy_set_header”指令中的参数数量无效。您怀疑哪个对 proxy_set_header 的调用是罪魁祸首?
    猜你喜欢
    • 2010-12-20
    • 1970-01-01
    • 2015-07-23
    • 2013-01-07
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多