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

feat(nginx): Allow logging settings as site/combined/none

This commit is contained in:
Gavin D'souza 2022-08-04 12:33:25 +05:30
parent 391dcf1e12
commit 5370129283
3 changed files with 16 additions and 5 deletions

View File

@ -25,13 +25,16 @@ def setup_sudoers(user):
@click.command("nginx", help="Generate configuration files for NGINX") @click.command("nginx", help="Generate configuration files for NGINX")
@click.option(
"--logging", default="combined", type=click.Choice(["none", "site", "combined"])
)
@click.option( @click.option(
"--yes", help="Yes to regeneration of nginx config file", default=False, is_flag=True "--yes", help="Yes to regeneration of nginx config file", default=False, is_flag=True
) )
def setup_nginx(yes=False): def setup_nginx(yes=False, logging="combined"):
from bench.config.nginx import make_nginx_conf from bench.config.nginx import make_nginx_conf
make_nginx_conf(bench_path=".", yes=yes) make_nginx_conf(bench_path=".", yes=yes, logging=logging)
@click.command("reload-nginx", help="Checks NGINX config file and reloads service") @click.command("reload-nginx", help="Checks NGINX config file and reloads service")

View File

@ -13,7 +13,7 @@ from bench.bench import Bench
from bench.utils import get_bench_name from bench.utils import get_bench_name
def make_nginx_conf(bench_path, yes=False): def make_nginx_conf(bench_path, yes=False, logging=None):
conf_path = os.path.join(bench_path, "config", "nginx.conf") conf_path = os.path.join(bench_path, "config", "nginx.conf")
if not yes and os.path.exists(conf_path): if not yes and os.path.exists(conf_path):
@ -43,6 +43,7 @@ def make_nginx_conf(bench_path, yes=False):
"allow_rate_limiting": allow_rate_limiting, "allow_rate_limiting": allow_rate_limiting,
# for nginx map variable # for nginx map variable
"random_string": "".join(random.choice(string.ascii_lowercase) for i in range(7)), "random_string": "".join(random.choice(string.ascii_lowercase) for i in range(7)),
"logging": logging,
} }
if allow_rate_limiting: if allow_rate_limiting:

View File

@ -114,10 +114,17 @@ server {
{% endfor -%} {% endfor -%}
# logs in var {%- if logging == "site" -%}
access_log /var/log/nginx/{{ site_name }}_access.log main; access_log /var/log/nginx/{{ site_name }}_access.log main;
error_log /var/log/nginx/{{ site_name }}_error.log; error_log /var/log/nginx/{{ site_name }}_error.log;
{%- elif logging == "combined" -%}
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
{%- endif %}
# optimizations # optimizations
sendfile on; sendfile on;