gpt4 book ai didi

symfony - Nginx symfony "invalid number of arguments in "try_files“指令”

转载 作者:行者123 更新时间:2023-12-02 15:58:22 24 4
gpt4 key购买 nike

我正在对我的 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 结合。

最佳答案

对于将来发现此问题的任何人,

如果您在 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;'"

关于symfony - Nginx symfony "invalid number of arguments in "try_files“指令”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52270767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com