AWS ElasticBeanstalk Nginx速率限制不适用于Node.js应用程序

时间:2018-07-06 11:15:26

标签: node.js amazon-web-services nginx elastic-beanstalk

这是文件rate-limit.nginx.config,我将其放置在Node应用程序的.ebextensions文件夹中。

files:
"/etc/nginx/conf.d/00_proxy.conf":
    mode: "000755"
    owner: root
    group: root
    content: |

        upstream nodejs_new {
            server 127.0.0.1:8081;
            keepalive 256;
        }

        limit_req_zone $binary_remote_addr zone=loginlimit:10m rate=5r/s;

        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_new;
                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/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;


        location /.well-known/acme-challenge {
            alias /var/app/current/public/letsencrypt;
        }

        location /auth/generateotp/ {
            limit_req zone=loginlimit;
        }

        location /auth/verifyotp/ {
            limit_req zone=loginlimit;
        } 

        }
container_commands:
    01_reload_nginx:
        command: "sudo service nginx reload"
    02_remove_config:
        command: "rm -f /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf"

一旦部署了该文件,我便将ssh放入实例中,并确保/etc/nginx/conf.d/00_proxy.conf文件存在。

我正在使用ab工具测试/ auth / generateotp,该API可以接受任意数量的并发请求,而它应该在一秒钟内仅接受5个请求。

这里可能是什么问题?

0 个答案:

没有答案