首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修改AWS弹性豆秆上的Nginx配置

如何修改AWS弹性豆秆上的Nginx配置
EN

Stack Overflow用户
提问于 2015-09-02 09:40:17
回答 1查看 2.2K关注 0票数 4

我正在尝试修改Nginx配置,以便部署ElasticBean秸秆。默认配置是:-

代码语言:javascript
复制
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;


}

我尝试将附加命令添加到location节点:-

代码语言:javascript
复制
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;

我最初尝试在我的.ebextensions中添加以下内容:

代码语言:javascript
复制
    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-ing到EC2实例时,我可以看到文件并没有从原始文件中更改。然后,我做了一些更多的研究,建议在运行/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf文件之后部署.ebextensions

  1. http://finik.net/2014/10/29/Beanstalk/
  2. Nginx config file overwritten during Elastic Beanstalk deployment?

因此,我尝试了以下方法:-

代码语言:javascript
复制
    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-ing中,我可以看到/tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf也没有被修改。

所以现在我被困住了。我有什么选择?

EN

回答 1

Stack Overflow用户

发布于 2016-06-10 14:26:37

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

您可以拥有这样的.ebextensions文件:

代码语言:javascript
复制
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的脚本(yu可以使用您想要的名称)。脚本在豆茎部署配置后执行。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32349719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档