【问题标题】:Nginx symfony "invalid number of arguments in "try_files" directive"Nginx symfony““try_files”指令中的参数数量无效”
【发布时间】:2018-09-11 07:27:16
【问题描述】:

我正在对我的 symfony 应用程序进行 dockerizing,但我不知道为什么会出现以下错误:

web_1  | 2018/09/11 07:21:40 [emerg] 1#1: invalid number of arguments in "try_files" directive in /etc/nginx/conf.d/default.conf:6
web_1  | nginx: [emerg] invalid number of arguments in "try_files" directive in /etc/nginx/conf.d/default.conf:6

这是我的配置:

server {
    server_name localhost;
    root /application/web;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/(index)\.php(/|$) {
        fastcgi_pass php:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }

    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

到目前为止,这是我的 docker-compose.yml:

version: "3"
services:
    web:
        image: nginx:latest
        volumes:
            - ./docker/nginx/default.template:/etc/nginx/conf.d/default.template
            - ./:/application
        ports:
            - "8080:80"
        links:
            - php
        environment:
            - NGINX_HOST=localhost
            - NGINX_PORT=80
        command: /bin/bash -c "envsubst < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"

    php:
        image: php:7.2-fpm

目前我只是想让 NGINX 运行而不会导致配置错误。我不希望 symfony 应用程序本身能够工作。只是 NGINX 结合 PHP-fpm。

【问题讨论】:

  • try_files 确实需要至少两个参数,但看起来你有它们。您是否尝试过使用更简单的论点?就像index.php /index.php
  • 是的,我有。当我使用 / 而不是 $uri 时,它工作正常。
  • 好吧,文档 (nginx.org/en/docs/http/ngx_http_core_module.html#try_files) 确实指定第一个参数需要是一个文件。可能是这样..
  • 当我从 docker-compose 中删除 envsubst /etc/nginx/conf.d/default.conf 部分时,它以某种方式得到了修复。 yml

标签: symfony docker nginx docker-compose


【解决方案1】:

对于以后发现此问题的任何人,

如果您在 docker-compose.yml 中使用 Docker 和 envsubst,就像 Docker NGINX README 告诉您的那样,这可能会导致问题。基本上,它会从您的 NGINX 配置中删除像 $uri 这样的变量,从而导致这样的错误。

https://github.com/docker-library/docs/issues/496 有一个问题(有解决方案)

示例:

之前(在docker-compose.yml中)

command: /bin/sh -c "envsubst < /etc/nginx/conf.d/app.template > /etc/nginx/conf.d/app.conf && exec nginx -g 'daemon off;'"

之后:

command: /bin/sh -c "envsubst '$$NGINX_HOST' < /etc/nginx/conf.d/app.template > /etc/nginx/conf.d/app.conf && exec nginx -g 'daemon off;'"

【讨论】:

    猜你喜欢
    • 2013-06-25
    • 2017-02-19
    • 2019-01-06
    • 2014-01-16
    • 1970-01-01
    • 2017-01-21
    • 2013-12-23
    • 2016-01-05
    • 2016-05-01
    相关资源
    最近更新 更多