mirror of
https://github.com/frappe/bench.git
synced 2025-01-10 09:02:10 +00:00
Merge pull request #287 from shreyasp/bench/rate_limit_conn
[Fix] Add 'allow_rate_limiting' as common_site_config to generate nginx config as per requirement
This commit is contained in:
commit
73f74bd9bd
@ -11,24 +11,30 @@ def make_nginx_conf(bench_path, yes=False):
|
||||
|
||||
config = get_config(bench_path)
|
||||
sites = prepare_sites(config, bench_path)
|
||||
|
||||
bench_name = get_bench_name(bench_path)
|
||||
bench_name_hash = hashlib.sha256(bench_name).hexdigest()[:16]
|
||||
|
||||
nginx_conf = template.render(**{
|
||||
allow_rate_limiting = config.get('allow_rate_limiting', False)
|
||||
|
||||
template_vars = {
|
||||
"sites_path": sites_path,
|
||||
"http_timeout": config.get("http_timeout"),
|
||||
"sites": sites,
|
||||
"webserver_port": config.get('webserver_port'),
|
||||
"socketio_port": config.get('socketio_port'),
|
||||
"bench_name": bench_name,
|
||||
"bench_name_hash": bench_name_hash,
|
||||
"limit_conn_shared_memory": get_limit_conn_shared_memory(),
|
||||
"error_pages": get_error_pages(),
|
||||
|
||||
"allow_rate_limiting": allow_rate_limiting,
|
||||
# for nginx map variable
|
||||
"random_string": "".join(random.choice(string.ascii_lowercase) for i in xrange(7))
|
||||
})
|
||||
}
|
||||
|
||||
if allow_rate_limiting:
|
||||
template_vars.update({
|
||||
'bench_name_hash': hashlib.sha256(bench_name).hexdigest()[:16],
|
||||
'limit_conn_shared_memory': get_limit_conn_shared_memory()
|
||||
})
|
||||
|
||||
nginx_conf = template.render(**template_vars)
|
||||
|
||||
conf_path = os.path.join(bench_path, "config", "nginx.conf")
|
||||
if not yes and os.path.exists(conf_path):
|
||||
|
@ -21,7 +21,9 @@ server {
|
||||
|
||||
root {{ sites_path }};
|
||||
|
||||
{% if allow_rate_limiting %}
|
||||
limit_conn per_host_{{ bench_name_hash }} 8;
|
||||
{% endif %}
|
||||
|
||||
{% if ssl_certificate and ssl_certificate_key %}
|
||||
ssl on;
|
||||
@ -141,7 +143,9 @@ upstream {{ bench_name}}-socketio-server {
|
||||
server 127.0.0.1:{{ socketio_port or 3000 }} fail_timeout=0;
|
||||
}
|
||||
|
||||
{% if allow_rate_limiting %}
|
||||
limit_conn_zone $host zone=per_host_{{ bench_name_hash }}:{{ limit_conn_shared_memory }}m;
|
||||
{% endif %}
|
||||
|
||||
# setup maps
|
||||
{%- set site_name_variable="$host" %}
|
||||
|
Loading…
Reference in New Issue
Block a user