Discourse socketed: outer nginx rate limiting when opening emoticons

HA! (again)

I found a way to disable the rate limiting only for my discourse server:

#=================================================
#               Rate limit EVERYTHING!!!!!!! (:blush: except for discourse)

map $http_host $rate_limit_except_discourse {
    "chat.tbp.land"     "";                 # in case of an empty string, limit_req_zone won't be applied!
    default             $binary_remote_addr;
}

# log_format derp '[$time_local] "$http_host" >$rate_limit_except_discourse<';
# access_log /var/log/nginx/derp.log derp;

# rate limiting zones
limit_req_zone $rate_limit_except_discourse zone=flood:10m rate=15r/s;
limit_req_status 429;

limit_conn_zone $rate_limit_except_discourse zone=connperip:10m;
limit_conn_status 429;

# rate limiting zones are applied for all servers!
limit_conn connperip 20;
limit_req zone=flood burst=20 nodelay;

#=================================================

I create a new variable named $rate_limit_except_discourse in which, based on $http_host i enable or disable rate limiting: when chat.tbp.land == $http_host then $rate_limit_except_discourse will have the value "" (nothing), and for all the other websites (by using the default keyword) i use the normal $binary_remote_addr;.

In this way I don’t have to copy-pasta the same lines in all my servers and the rate limiting is left for inner nginx (the one in the discourse container).


SUCCES! :triumph:

4 Likes