nus*_*000 1 nginx symfony docker docker-compose
我正在对我的symfony应用程序进行docker化,但是我无法弄清楚为什么会出现以下错误:
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结合使用。
对于以后发现这个问题的任何人,
如果您使用的是Docker,envsubst而您docker-compose.yml的Docker NGINX README告诉您这样做,则很可能会引起问题。基本上,它会$uri从您的NGINX配置中剥离出var ,从而导致此类错误。
在解决方案上有一个问题(https://github.com/docker-library/docs/issues/496)
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;'"
| 归档时间: | 
 | 
| 查看次数: | 609 次 | 
| 最近记录: |