Nginx config file overwritten during Elastic Beanstalk deployment?

前端 未结 6 2097
自闭症患者
自闭症患者 2020-11-29 04:52

I need to add p3p headers to the static resource location on a standard Nodejs & Nginx Elastic Beanstalk.

I\'ve created an ebextension script as exp

6条回答
  •  既然无缘
    2020-11-29 05:13

    Here are the latest instructions from Amazon, as of August 2018: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-proxy.html

    (I have just used these instructions to customize the Nginx proxy for a Node.js app on Elastic Beanstalk, and it works as expected.)

    Basically you use your own proxy.conf for Nginx, and remove the auto-generated stuff.

    # .ebextensions/proxy.config
    files:
      /etc/nginx/conf.d/proxy.conf:
        mode: "000644"
        owner: root
        group: root
        content: |
          upstream nodejs {
            server 127.0.0.1:5000;
            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 /static {
                alias /var/app/current/static;
            }
    
          }
    
      /opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh:
        mode: "000755"
        owner: root
        group: root
        content: |
          #!/bin/bash -xe
          rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
          service nginx stop 
          service nginx start
    
    container_commands:
     removeconfig:
        command: "rm -f /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf"
    

提交回复
热议问题