如何在 elastic beanstalk 中扩展 nginx 配置 (Amazon Linux 2)
How to extend nginx config in elastic beanstalk (Amazon Linux 2)
我按照建议 here 配置 nginx 反向代理以允许大于默认 1mb 的文件。所以,我的代码在
/.platform/nginx/conf.d/prod.conf
看起来像这样:
http {
client_max_body_size 30M;
}
然而,这似乎没有效果,当我尝试上传大于1mb的文件时,nginx仍然报错。
我也尝试在没有 http
和大括号的情况下执行此操作,如 this question 的已接受答案中所述,如下所示:
client_max_body_size 30M;
这也没有效果。
我认为应用配置后可能需要重新启动 nginx,所以我在 .ebextensions 目录中添加了一个名为 01nginx.config
的文件,如下所示:
commands:
01_reload_nginx:
command: "sudo service nginx reload"
这也没有效果。
我看过this question and the above-referenced question, as well as this one。但是,它们似乎都已过时或不适用于 Amazon Linux 2 实例,因为其中 none 提到了上述 elastic beanstalk 文档中的 .platform
目录。无论如何,到目前为止,none 他们的回答对我有用。那么,我错过了什么?
好的,经过多次尝试,我能够像这样解决这个问题:
在 .ebextensions 目录中添加一个名为 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。这不是 elastic beanstalk linux platforms documentation.
中记录的方式
我在转移到亚马逊时遇到了类似的问题Linux 2.
只需在 .platform/nginx/conf.d/
创建一个名为 proxy.conf
的文件并包含以下内容对我来说就足够了。
client_max_body_size 50M;
如果你仔细研究 nginx 的主要配置,你会看到这个文件是如何包含在文件中间的,所以不需要用 http 包装它。
这类似于 adam tropp 的回答,但它遵循 AWS 给出的示例
以下对我有用:
~/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
几天来我也遇到了同样的问题,最后我按照以下步骤解决了:
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;
}
}
}
我按照建议 here 配置 nginx 反向代理以允许大于默认 1mb 的文件。所以,我的代码在
/.platform/nginx/conf.d/prod.conf
看起来像这样:
http {
client_max_body_size 30M;
}
然而,这似乎没有效果,当我尝试上传大于1mb的文件时,nginx仍然报错。
我也尝试在没有 http
和大括号的情况下执行此操作,如 this question 的已接受答案中所述,如下所示:
client_max_body_size 30M;
这也没有效果。
我认为应用配置后可能需要重新启动 nginx,所以我在 .ebextensions 目录中添加了一个名为 01nginx.config
的文件,如下所示:
commands:
01_reload_nginx:
command: "sudo service nginx reload"
这也没有效果。
我看过this question and the above-referenced question, as well as this one。但是,它们似乎都已过时或不适用于 Amazon Linux 2 实例,因为其中 none 提到了上述 elastic beanstalk 文档中的 .platform
目录。无论如何,到目前为止,none 他们的回答对我有用。那么,我错过了什么?
好的,经过多次尝试,我能够像这样解决这个问题:
在 .ebextensions 目录中添加一个名为 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。这不是 elastic beanstalk linux platforms documentation.
中记录的方式我在转移到亚马逊时遇到了类似的问题Linux 2.
只需在 .platform/nginx/conf.d/
创建一个名为 proxy.conf
的文件并包含以下内容对我来说就足够了。
client_max_body_size 50M;
如果你仔细研究 nginx 的主要配置,你会看到这个文件是如何包含在文件中间的,所以不需要用 http 包装它。
这类似于 adam tropp 的回答,但它遵循 AWS 给出的示例
以下对我有用:
~/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
几天来我也遇到了同样的问题,最后我按照以下步骤解决了:
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;
}
}
}