2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-10 09:02:10 +00:00

[Fix] Add 'allow_rate_limiting' as common_site_config to generate nginx config as per requirement

This commit is contained in:
shreyas 2016-08-03 14:54:45 +05:30
parent ba772ae51c
commit 4e45c7b34b
2 changed files with 17 additions and 7 deletions

View File

@ -11,25 +11,31 @@ 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):
click.confirm('nginx.conf already exists and this will overwrite it. Do you want to continue?',

View File

@ -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" %}