nusje2000
nusje2000

Reputation: 503

Nginx symfony "invalid number of arguments in "try_files" directive"

I am working on dockerizing my symfony application, but I cant figure out why the following error occours:

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

This is my config:

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;
}

This is my docker-compose.yml so far:

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

Currently I am just trying to get NGINX running without resulting in config errors. I don't expect the symfony application itself to work. Just NGINX combined with PHP-fpm.

Upvotes: 2

Views: 3240

Answers (1)

simshaun
simshaun

Reputation: 21466

For anyone finding this question in the future,

If you're using Docker and envsubst in your docker-compose.yml like the Docker NGINX README tells you to do, that's likely causing the problem. Basically, it is stripping out vars like $uri from your NGINX config, leading to errors like this.

There's an issue on it (with the solution) at https://github.com/docker-library/docs/issues/496

Example:

Before (in 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;'"

After:

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

Upvotes: 16

Related Questions