如何修改AWS Elastic Beanstalk上的Nginxconfiguration

我正在尝试修改Elastic Beanstalk部署的Nginxconfiguration。 默认configuration是: –

upstream nodejs { server 127.0.0.1:8081; keepalive 256; } server { listen 8080; if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") { set $year $1; set $month $2; set $day $3; set $hour $4; } access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd; access_log /var/log/nginx/access.log main; location / { proxy_pass http://nodejs; 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; } gzip on; gzip_comp_level 4; gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; } 

我试图添加额外的命令到位置节点: –

 chunked_transfer_encoding off; proxy_buffering off; proxy_cache off; 

我最初尝试将以下内容添加到我的.ebextensions

  files: "/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf" : mode: "000644" owner: root group: root content: | upstream nodejs { server 127.0.0.1:8081; keepalive 256; } server { listen 8080; if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") { set $year $1; set $month $2; set $day $3; set $hour $4; } access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd; access_log /var/log/nginx/access.log main; location / { proxy_pass http://nodejs; proxy_set_header Connection ""; proxy_http_version 1.1; chunked_transfer_encoding off; proxy_buffering off; proxy_cache off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } gzip on; gzip_comp_level 4; gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; } 

但是,在SSH到EC2实例中,我可以看到该文件没有从原来的变化。 然后我做了一些更多的研究,提示在.ebextensions文件运行 ,/ .ebextensions /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf被部署。

  1. http://finik.net/2014/10/29/Beanstalk/
  2. 在Elastic Beanstalk部署过程中覆盖Nginxconfiguration文件?

所以我尝试了以下代替:

  files: "/tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf" : mode: "000755" owner: root group: root content: | upstream nodejs { server 127.0.0.1:8081; keepalive 256; } server { listen 8080; if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") { set $year $1; set $month $2; set $day $3; set $hour $4; } access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd; access_log /var/log/nginx/access.log main; location / { proxy_pass http://nodejs; proxy_set_header Connection ""; proxy_http_version 1.1; chunked_transfer_encoding off; proxy_buffering off; proxy_cache off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } gzip on; gzip_comp_level 4; gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; } 

同样,通过SSH连接到实例中,我可以看到/tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf都不会被修改。

所以现在我很困难。 我有什么select?

有效的是编写一个更新00_elastic_beanstalk_proxy.conf文件的sed脚本(通过搜索和替换)并在container_command钩子上运行所述脚本。

你可以有这样一个.ebextensions文件:

 files: /tmp/deployment/custom_mod_nginx.sh: mode: "000755" content: | sed -i 's/proxy_http_version 1.1;/ proxy_http_version 1.1;\n chunked_transfer_encoding off;\n proxy_buffering off;\n proxy_cache off;\n/' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf container_commands: nginx_real_ip: command: "/tmp/deployment/custom_mod_nginx.sh" 

这将做什么是创建一个名为custom_mod_nginx.shcustom_mod_nginx.sh可以使用你想要的名称)的脚本。 脚本在beanstalk部署配置后执行。