apache aws弹性beanstalk“请求URI太长”

ndasle7k  于 2022-11-30  发布在  Apache
关注(0)|答案(3)|浏览(173)

我有一个在弹性豆茎上运行python flask 应用程序的安装程序。我的问题是我得到了这个414错误代码。我已经将LimitRequestLine 200000添加到httpd.conf,并在ec2示例的shell上用sudo httpd service restart重新启动,但它似乎没有做到这一点。
这对于运行在ec2上而不是弹性beanstalk上的apache服务器来说是完美的。
我真的很感激你能帮我...
另一件奇怪的事情-如果我从ec2示例上的shell重启httpd服务,长uri可以传递一次,并且只有一次-第二次我再次得到414。
谢谢

tjrkku2a

tjrkku2a1#

另一种方法是直接修改负载平衡器以增加参数“large_client_header_buffers”。这可能需要应用负载平衡器(与默认的传统负载平衡器相比)。
例如,在.ebextensions文件夹中创建文件files.config

files:
  "/etc/nginx/conf.d/proxy.conf":
    mode: "000755"
    owner: root
    group: root
    content: |
     large_client_header_buffers 16 1M;
bvhaajcl

bvhaajcl2#

LimitRequestLine应该位于<VirtualHost>部分中。在Elastic Beanstalk中做这件事相当棘手,因为您需要将此行添加到/etc/httpd/conf.d/wsgi.conf中,而/etc/httpd/conf.d/wsgi.conf是在运行commandscontainer_commands * 之后 * 自动生成的。按照this博客中的想法,将以下内容添加到.ebextensions下的配置文件中:

commands:
  create_post_dir:
    command: "mkdir -p /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/99_adjust_request_limit.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      sed -i.back '/<VirtualHost/aLimitRequestLine 100000' /etc/httpd/conf.d/wsgi.conf
      supervisorctl -c /opt/python/etc/supervisord.conf restart httpd
hec6srdp

hec6srdp3#

由于我在EB中使用了Docker平台,或者是因为最近情况发生了变化,这些答案对我都不起作用。我通过从/etc/nginx/nginx.conf(在一个正在运行的EB示例中)获取默认的nginx.conf,然后添加“large_client_header_buffers 16 1 M;“指向Docker应用程序的proxy_pass指令中。
然后将nginx.conf文件放在.platform/nginx下(因为nginx配置将忽略.ebextensions)。
您的配置文件可能会有所不同,所以我建议使用该配置文件,但这是我的工作文件:

# Elastic Beanstalk Nginx Configuration File
# For docker platform. Copied from /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
worker_rlimit_nofile 67114;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';

    include conf.d/*.conf;

    map $http_upgrade $connection_upgrade {
        default "upgrade";
    }

    server {
        listen 80 default_server;
        gzip on;
        gzip_comp_level 4;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        # Custom config to avoid http error 414 on large POST requests
        large_client_header_buffers 16 1M;

        access_log /var/log/nginx/access.log main;

        location / {
            proxy_pass http://docker;
            proxy_http_version 1.1;

            proxy_set_header Connection $connection_upgrade;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        # Include the Elastic Beanstalk generated locations
        include conf.d/elasticbeanstalk/*.conf;
    }
}

相关问题