【发布时间】: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