gpt4 book ai didi

amazon-web-services - 如何修改 AWS Elastic Beanstalk 上的 Nginx 配置

转载 作者:行者123 更新时间:2023-12-01 05:01:22 32 4
gpt4 key购买 nike

我正在尝试修改 Nginx 我的 的配置 Elastic Beanstalk 部署。默认配置是:-

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得到修改。

    所以现在我很困。我有哪些选择?

    最佳答案

    有效的是编写一个 sed 脚本来更新 00_elastic_beanstalk_proxy.conf文件(通过搜索和替换)并在 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.sh 的脚本。 (你可以使用你想要的名字)。该脚本在 beanstalk 部署配置后执行。

    关于amazon-web-services - 如何修改 AWS Elastic Beanstalk 上的 Nginx 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32349719/

    32 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com