【发布时间】:2015-11-27 18:12:55
【问题描述】:
我正在尝试为我的 Elastic Beanstalk 部署修改 Nginx 配置。默认配置是:-
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 实例时,我可以看到该文件与原始文件没有任何变化。然后我做了一些更多的研究,建议在/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf 被部署 .ebextensions 文件运行之后。
- http://finik.net/2014/10/29/Beanstalk/
- Nginx config file overwritten during Elastic Beanstalk deployment?
所以我尝试了以下方法:-
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 都没有被修改。
所以现在我很困。我有哪些选择?
【问题讨论】:
-
.ebextensions格式为 YAML 或 JSON。而且,您的配置格式是 YAML。 YAML 需要正确的缩进。在上面的配置中,缩进看起来是错误的(files:和"/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf" :不应该在同一个缩进中)。
标签: amazon-web-services nginx amazon-ec2 amazon-elastic-beanstalk