5

我按照这里的建议配置 nginx 反向代理以允许大于默认 1mb 的文件。因此,我的代码 /.platform/nginx/conf.d/prod.conf 如下所示:

http {
  client_max_body_size 30M;
}

但是,这似乎没有任何效果,当我尝试上传大于 1mb 的文件时,nginx 仍然会报错。

我也尝试在没有和大括号的情况下执行此操作,如对此问题http的已接受答案中所述,如下所示:

client_max_body_size 30M;

这也没有效果。

我认为应用配置后可能需要重新启动 nginx,所以我在 .ebextensions 目录中添加了一个名为 的文件,01nginx.config如下所示:

commands:
  01_reload_nginx: 
    command: "sudo service nginx reload"

这也没有效果。

我已经看过这个问题和上面提到的问题,以及这个问题。但是,它们似乎都已过时或不适用于 Amazon Linux 2 实例,因为它们都没有提到.platform上述弹性 beanstalk 文档中的目录。无论如何,到目前为止,他们的答案都没有对我有用。那么,我错过了什么?

4

4 回答 4

19

在迁移到 Amazon Linux 2 时,我遇到了类似的问题。

.platform/nginx/conf.d/对我来说,只需在调用时创建一个proxy.conf包含以下内容的文件就足够了。

client_max_body_size 50M;

如果你去挖掘 nginx 的主要配置,你会看到这个文件是如何包含在文件中间的,所以不需要用 http 包裹它。

这类似于 adam tropp 的答案,但它遵循 AWS 给出的示例

于 2020-06-22T13:00:31.190 回答
3

下面为我​​工作:

~/my-app/
|-- web.jar
|-- Procfile
|-- readme.md
|-- .ebextensions/
|   |-- options.config        # Option settings
|   `-- cloudwatch.config     # Other .ebextensions sections, for example files and container commands
`-- .platform/
    |-- nginx/                # Proxy configuration
    |   |-- nginx.conf
    |   `-- conf.d/
    |       `-- custom.conf
于 2020-10-23T20:59:37.107 回答
0

好的,经过多次尝试,我能够像这样解决这个问题:

在 .ebextenstions 目录中添加一个名为的文件01_reverse_proxy.config(名称无关紧要,我认为只是 .config 部分)

在该文件中,准确放置以下内容:

files:
  "/etc/nginx/conf.d/proxy.conf" :
  mode: "000755"
  owner: root
  group: root
  content: |
    client_max_body_size 30M;
commands:
  01_reload_nginx:
    command: "service nginx reload"

具有适当的 YAML 间距。这解决了包括 Rails、Puma 和 Amazon Linux 2.11.4 在内的堆栈上的问题。这不是弹性 beanstalk linux 平台文档中记录的方式。

于 2020-04-21T15:15:21.507 回答
0

这几天我遇到了同样的问题,最后我按照以下步骤解决了:

1 在这个路由中创建一个文件 .platform/nginx/nginx.conf

文件 nginx.conf

events {}

http {
    server {
        listen      80;
        server_name project-jndxpewg.eu-west-2.elasticbeanstalk.com;
        client_max_body_size 64M;

        include /etc/nginx/fastcgi_params;


         # in my case this is the project public folder
        root /var/www/html/webroot;
        index index.php;

        access_log  /var/log/nginx/access.log;
        error_log   /var/log/nginx/error.log;

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

        location ~ \.php$ {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass  unix:/var/run/php-fpm/www.sock;
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

    }
}
于 2021-11-25T08:12:40.937 回答