如何从EB响应中删除标头

问题描述 投票:1回答:1

我正在尝试从EB服务中删除响应头。

EB配置:64bit Amazon Linux 2017.03 v2.7.1 running Docker 17.03.1-ce

哪个运行:FROM python:3.6.1

也使用flask

我将以下代码添加到flask

def after_request_callback(response):
    response.headers["server"] = "SomeNonFingerprintValue"
    return response


def create_application():
    application = Flask(__name__)
    application.after_request(after_request_callback)

这在我本地运行时工作正常,但是当我部署到EB时,我不断获得指纹值:server → nginx/1.10.3

知道如何删除\修改已部署服务的此值?

python amazon-web-services docker flask elastic-beanstalk
1个回答
1
投票
  1. 在项目的根目录中创建“.ebextensions”文件夹
  2. 添加一个名为'nginx.config'的文件(可以调用任何东西,只要它以.config结尾)
  3. 将以下内容放在文件中(注意proxy_set_header行): files: "/tmp/000_my_nginx_config.conf": mode: "000644" owner: root group: root content: | upstream nodejs { server 127.0.0.1:8081; keepalive 256; } log_format combined_no_query '$remote_addr - $remote_user [$time_local] ' '"$uri" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent"'; 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 combined_no_query; 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_set_header Server NonFingerprint; } 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; } "/tmp/45_replace_config.sh": mode: "000644" owner: root group: root content: | #! /bin/bash cp -rfv /tmp/000_my_nginx_config.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf container_commands: 00_appdeploy_rewrite_hook: command: cp -v /tmp/45_replace_config.sh /opt/elasticbeanstalk/hooks/appdeploy/enact 01_appdeploy_rewrite_hook: command: cp -v /tmp/45_replace_config.sh /opt/elasticbeanstalk/hooks/configdeploy/enact 02_rewrite_hook_perms: command: chmod 755 /opt/elasticbeanstalk/hooks/appdeploy/enact/45_replace_config.sh /opt/elasticbeanstalk/hooks/configdeploy/enact/45_replace_config.sh 03_rewrite_hook_ownership: command: chown root:users /opt/elasticbeanstalk/hooks/appdeploy/enact/45_replace_config.sh /opt/elasticbeanstalk/hooks/configdeploy/enact/45_replace_config.sh
© www.soinside.com 2019 - 2024. All rights reserved.