7
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-06-18 13:22:22 +00:00

Add scheme and server name to access logs

To do so, we had to create a new log_format.

Plugin developers are strongly encouraged to start using this log format
by adding the `access_log /var/log/nginx/access.log tutor;` directive to
their extra nginx configurations.

In order to load this log format early, the `tutor.conf` config file had
to be renamed to something early in the alphabet... (hence starting by
an underscore) Older users would face an error on nginx reload, so older
"tutor.conf" files are automatically removed on config save.
This commit is contained in:
Régis Behmo 2020-03-12 11:59:50 +01:00
parent 0cf8958e3a
commit 08606ca1a6
6 changed files with 23 additions and 5 deletions

View File

@ -4,6 +4,7 @@ Note: Breaking changes between versions are indicated by "💥".
## Unreleased
- [Improvement] Modify nginx access logs to include request scheme and server name (plugin developers should use the "tutor" log format)
- [Bugfix] Fix DNS resolution of restarted service
- [Feature] Restart multiple services with `local restart`
- [Feature] Make it possible to easily reload openedx gunicorn process with `tutor local exec lms reload-gunicorn``

View File

@ -181,9 +181,18 @@ def save(root, config):
if plugin.templates_root:
save_plugin_templates(plugin, root, config)
upgrade_obsolete(root)
fmt.echo_info("Environment generated in {}".format(base_dir(root)))
def upgrade_obsolete(root):
# tutor.conf was renamed to _tutor.conf in order to be the first config file loaded
# by nginx
nginx_tutor_conf = pathjoin(root, "apps", "nginx", "tutor.conf")
if os.path.exists(nginx_tutor_conf):
os.remove(nginx_tutor_conf)
def save_plugin_templates(plugin, root, config):
"""
Save plugin templates to plugins/<plugin name>/*.

View File

@ -0,0 +1,10 @@
# Allow long domain names
server_names_hash_bucket_size 128;
# Set a short ttl for proxies to allow restarts
resolver 127.0.0.1 [::1]:5353 valid=10s;
# Configure logging to include scheme and server name
log_format tutor '$remote_addr - $remote_user [$time_local] $scheme://$host "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

View File

@ -20,6 +20,7 @@ server {
ssl_certificate_key /etc/letsencrypt/live/{{ LMS_HOST }}/privkey.pem;
{% endif %}
access_log /var/log/nginx/access.log tutor;
client_max_body_size 100M;
server_tokens off;

View File

@ -7,6 +7,7 @@ upstream lms-backend {
server {
server_name {{ LMS_HOST }} preview.{{ LMS_HOST }};
listen 80;
access_log /var/log/nginx/access.log tutor;
return 301 https://$server_name$request_uri;
}
{% endif %}
@ -20,6 +21,7 @@ server {
ssl_certificate_key /etc/letsencrypt/live/{{ LMS_HOST }}/privkey.pem;
{% endif %}
access_log /var/log/nginx/access.log tutor;
client_max_body_size 4M;
server_tokens off;

View File

@ -1,5 +0,0 @@
# Allow long domain names
server_names_hash_bucket_size 128;
# Set a short ttl for proxies to allow restarts
resolver 127.0.0.1 [::1]:5353 valid=10s;