![](/img/trans.png)
[英]Uploading codeigniter project on amazon web services using elastic beanstalk
[英]How to change nginx config in amazon elastic beanstalk running a docker instance
在我登錄並設置 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:
亞馬遜實際上建議編輯nginx部署文件的暫存版本。 有幾個位於/tmp/deployment/config/
,一個用於編輯一般的'http'上下文,然后一些用於配置服務器的不同方面。
我想將緩存功能附加到默認代理服務器,因此我編寫了一個.ebextensions
配置文件來替換#etc#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
我還需要修改nginx配置。
/etc/nginx/sites-enabled/elasticbeanstalk-nginx-docker.conf
)並重新啟動nginx服務( service nginx restart
)。 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"
現在這對我的項目很有效( 這里是您可以看到它的動作源)。
擴展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
是將在Elastic Beanstalk EC2實例上創建的文件名。 默認情況下,此配置位於文件/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
。 因此,如果您使用000作為前綴,則可以保證您的配置將首先考慮在內。
內容已從默認的nginx配置( /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
再次)復制,然后使用我自己的配置進行自定義。
更簡潔的方法(如果您在Elastic Beanstalk上使用Java或Go平台)是在.ebextensions中的子文件夾中包含您希望的更改的nginx .conf文件:
您現在可以在.ebextensions / nginx文件夾中放置nginx.conf文件以覆蓋Nginx配置。 您還可以將配置文件放在.ebextensions / nginx / conf.d文件夾中,以便將它們包含在平台提供的Nginx配置中。
2022 年 2 月 2 日更新
似乎 AWS 在使用 Amazon Linux 2 的較新版本的 Elastic Beanstalk 中更改了一些內容,因此如果您將 EBS 與 Amazon Linux2 一起使用, @jsebfranck<\/a>提到的方法將不再適用。
較新的方法是在 zip 包的根目錄中創建一個“.platform”文件夾,並將 nginx.conf 文件添加到“.\/platform\/nginx\/nginx.conf”,如果在該位置找到該文件,eb 引擎應該交換該文件。
有關詳細信息,請參見此處: https<\/a> :\/\/docs.aws.amazon.com\/elasticbeanstalk\/latest\/dg\/using-features.migration-al.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.