After i login and the cookie is set I get error 502. When i read the log i get the error:
在我登录并设置cookie后,我得到错误502.当我读取日志时,我收到错误:
014/05/17 01:54:43 [error] 11013#0: *8 upstream sent too big header while reading response
header from upstream, client: 83.248.134.236, server: , request: "GET /administration
HTTP/1.1", upstream:
After some fast googling i found: http://developernote.com/2012/09/how-i-fixed-nginx-502-bad-gateway-error/
经过一些快速的谷歌搜索后,我发现:http://developernote.com/2012/09/how-i-fixed-nginx-502-bad-gateway-error/
and I want to try to set fastcgi_buffers and fastcgi_buffer_size to a different value. But how do i set variable on nginx in amazon elasticbeanstalk?
我想尝试将fastcgi_buffers和fastcgi_buffer_size设置为不同的值。但是如何在amazon elasticbeanstalk中设置nginx变量?
The nginx server is before my docker instance.
nginx服务器在我的docker实例之前。
4 个解决方案
#1
19
I also needed to modify the nginx configuration.
我还需要修改nginx配置。
- Create a script that modifies the nginx configuration (probably you want
/etc/nginx/sites-enabled/elasticbeanstalk-nginx-docker.conf
) and restarts the nginx service (service nginx restart
). - 创建一个修改nginx配置的脚本(可能需要/etc/nginx/sites-enabled/elasticbeanstalk-nginx-docker.conf)并重新启动nginx服务(service nginx restart)。
- You need to execute that script after this nginx config file is written which is after normal ebextensions are executed. This is undocumented, but Evan shared how to do this here: essentially you use an ebextension to copy the script into a directory with hooks that gets executed at the proper time.
- 在写入nginx配置文件之后,您需要执行该脚本,这是在执行正常的ebextensions之后。这是没有记录的,但Evan在这里分享了如何做到这一点:基本上你使用ebextension将脚本复制到一个带有钩子的目录,这些钩子在适当的时候被执行。
An example ebextension config is .ebextensions/01modify_nginx.config
:
ebextension配置示例是.ebextensions / 01modify_nginx.config:
container_commands:
copy:
command: "cp .ebextensions/01rewrite_nginx_config.py /opt/elasticbeanstalk/hooks/appdeploy/enact/"
make_exe:
command: "chmod +x /opt/elasticbeanstalk/hooks/appdeploy/enact/01rewrite_nginx_config.py"
This is working nicely now for my project (here is the source where you can see it in action).
现在这对我的项目很有效(这里是您可以看到它的动作源)。
#2
28
Amazon actually recommends editing the staging version of the nginx deployment file. There are several located at /tmp/deployment/config/
, one for editing the general 'http' context, and then a few for configuring different aspects of the server.
亚马逊实际上建议编辑nginx部署文件的暂存版本。有几个位于/ tmp / deployment / config /,一个用于编辑一般的'http'上下文,然后一些用于配置服务器的不同方面。
I wanted to attach caching functionality to the default proxy server, so I wrote an .ebextensions
config file to replace #etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
, which is then copied over to /etc/nginx/conf.d
during deployment. You can inline the file if its simple enough, but I put mine in S3 so that different applications and pull it down and use it. Here's the config file:
我想将缓存功能附加到默认代理服务器,因此我编写了一个.ebextensions配置文件来替换#etter #nginx#conf.d#00_elastic_beanstalk_proxy.conf,然后将其复制到/etc/nginx/conf.d期间部署。如果文件足够简单,你可以内联文件,但是我把它放在S3中,以便不同的应用程序将其拉下并使用它。这是配置文件:
commands:
01-get-nginx-conf-file:
command: aws s3 cp s3://<bucket-name>/custom-nginx.conf /home/ec2-user
container_commands:
01-replace-default-nginx-config:
command: mv -f /home/ec2-user/custom-nginx.conf /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
#3
16
Another way to extend Elastic Beanstalk nginx config is to create a file in the .ebextensions
directory, named for example nginx.config
with the following content :
扩展Elastic Beanstalk nginx配置的另一种方法是在.ebextensions目录中创建一个文件,例如nginx.config,其名称如下:
files:
"/etc/nginx/conf.d/000_my_config.conf":
content: |
upstream nodejsserver {
server 127.0.0.1:8081;
keepalive 256;
}
server {
listen 8080;
location / {
proxy_pass http://nodejsserver;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /myconfig {
proxy_pass http://my_proxy_pass_host;
}
}
/etc/nginx/conf.d/000_my_config.conf
is the filename which will be created on the Elastic Beanstalk EC2 instances. By default this configuration is in the file /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
. So if you prefix with 000, it guarantees you that your configuration will be taken into account first.
/etc/nginx/conf.d/000_my_config.conf是将在Elastic Beanstalk EC2实例上创建的文件名。默认情况下,此配置位于文件/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf中。因此,如果您使用000作为前缀,则可以保证您的配置将首先考虑在内。
The content has been copied from the default nginx configuration (/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
again), then customized with my own configuration.
内容已从默认的nginx配置(/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf再次)复制,然后使用我自己的配置进行自定义。
#4
4
A cleaner approach (if you're using the Java or Go platform on Elastic Beanstalk) is to have nginx .conf files with your wished changes in a subfolder in .ebextensions:
更简洁的方法(如果您在Elastic Beanstalk上使用Java或Go平台)是在.ebextensions中的子文件夹中包含您希望的更改的nginx .conf文件:
You can now place an nginx.conf file in the .ebextensions/nginx folder to override the Nginx configuration. You can also place configuration files in the .ebextensions/nginx/conf.d folder in order to have them included in the Nginx configuration provided by the platform.
您现在可以在.ebextensions / nginx文件夹中放置一个nginx.conf文件来覆盖Nginx配置。您还可以将配置文件放在.ebextensions / nginx / conf.d文件夹中,以便将它们包含在平台提供的Nginx配置中。
资源
#1
19
I also needed to modify the nginx configuration.
我还需要修改nginx配置。
- Create a script that modifies the nginx configuration (probably you want
/etc/nginx/sites-enabled/elasticbeanstalk-nginx-docker.conf
) and restarts the nginx service (service nginx restart
). - 创建一个修改nginx配置的脚本(可能需要/etc/nginx/sites-enabled/elasticbeanstalk-nginx-docker.conf)并重新启动nginx服务(service nginx restart)。
- You need to execute that script after this nginx config file is written which is after normal ebextensions are executed. This is undocumented, but Evan shared how to do this here: essentially you use an ebextension to copy the script into a directory with hooks that gets executed at the proper time.
- 在写入nginx配置文件之后,您需要执行该脚本,这是在执行正常的ebextensions之后。这是没有记录的,但Evan在这里分享了如何做到这一点:基本上你使用ebextension将脚本复制到一个带有钩子的目录,这些钩子在适当的时候被执行。
An example ebextension config is .ebextensions/01modify_nginx.config
:
ebextension配置示例是.ebextensions / 01modify_nginx.config:
container_commands:
copy:
command: "cp .ebextensions/01rewrite_nginx_config.py /opt/elasticbeanstalk/hooks/appdeploy/enact/"
make_exe:
command: "chmod +x /opt/elasticbeanstalk/hooks/appdeploy/enact/01rewrite_nginx_config.py"
This is working nicely now for my project (here is the source where you can see it in action).
现在这对我的项目很有效(这里是您可以看到它的动作源)。
#2
28
Amazon actually recommends editing the staging version of the nginx deployment file. There are several located at /tmp/deployment/config/
, one for editing the general 'http' context, and then a few for configuring different aspects of the server.
亚马逊实际上建议编辑nginx部署文件的暂存版本。有几个位于/ tmp / deployment / config /,一个用于编辑一般的'http'上下文,然后一些用于配置服务器的不同方面。
I wanted to attach caching functionality to the default proxy server, so I wrote an .ebextensions
config file to replace #etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
, which is then copied over to /etc/nginx/conf.d
during deployment. You can inline the file if its simple enough, but I put mine in S3 so that different applications and pull it down and use it. Here's the config file:
我想将缓存功能附加到默认代理服务器,因此我编写了一个.ebextensions配置文件来替换#etter #nginx#conf.d#00_elastic_beanstalk_proxy.conf,然后将其复制到/etc/nginx/conf.d期间部署。如果文件足够简单,你可以内联文件,但是我把它放在S3中,以便不同的应用程序将其拉下并使用它。这是配置文件:
commands:
01-get-nginx-conf-file:
command: aws s3 cp s3://<bucket-name>/custom-nginx.conf /home/ec2-user
container_commands:
01-replace-default-nginx-config:
command: mv -f /home/ec2-user/custom-nginx.conf /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
#3
16
Another way to extend Elastic Beanstalk nginx config is to create a file in the .ebextensions
directory, named for example nginx.config
with the following content :
扩展Elastic Beanstalk nginx配置的另一种方法是在.ebextensions目录中创建一个文件,例如nginx.config,其名称如下:
files:
"/etc/nginx/conf.d/000_my_config.conf":
content: |
upstream nodejsserver {
server 127.0.0.1:8081;
keepalive 256;
}
server {
listen 8080;
location / {
proxy_pass http://nodejsserver;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /myconfig {
proxy_pass http://my_proxy_pass_host;
}
}
/etc/nginx/conf.d/000_my_config.conf
is the filename which will be created on the Elastic Beanstalk EC2 instances. By default this configuration is in the file /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
. So if you prefix with 000, it guarantees you that your configuration will be taken into account first.
/etc/nginx/conf.d/000_my_config.conf是将在Elastic Beanstalk EC2实例上创建的文件名。默认情况下,此配置位于文件/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf中。因此,如果您使用000作为前缀,则可以保证您的配置将首先考虑在内。
The content has been copied from the default nginx configuration (/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
again), then customized with my own configuration.
内容已从默认的nginx配置(/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf再次)复制,然后使用我自己的配置进行自定义。
#4
4
A cleaner approach (if you're using the Java or Go platform on Elastic Beanstalk) is to have nginx .conf files with your wished changes in a subfolder in .ebextensions:
更简洁的方法(如果您在Elastic Beanstalk上使用Java或Go平台)是在.ebextensions中的子文件夹中包含您希望的更改的nginx .conf文件:
You can now place an nginx.conf file in the .ebextensions/nginx folder to override the Nginx configuration. You can also place configuration files in the .ebextensions/nginx/conf.d folder in order to have them included in the Nginx configuration provided by the platform.
您现在可以在.ebextensions / nginx文件夹中放置一个nginx.conf文件来覆盖Nginx配置。您还可以将配置文件放在.ebextensions / nginx / conf.d文件夹中,以便将它们包含在平台提供的Nginx配置中。
资源