Move logging to http section

This commit is contained in:
TheMaddax 2024-12-11 21:56:01 -06:00
parent 13d137847c
commit f0135e4e54

View file

@ -1,8 +1,6 @@
server { http {
listen 804; include /etc/nginx/mime.types;
server_name localhost; default_type application/octet-stream;
root /usr/share/nginx/html;
index index.html;
# Matomo tracking log format # Matomo tracking log format
log_format matomo_tracking '$remote_addr - $remote_user [$time_local] ' log_format matomo_tracking '$remote_addr - $remote_user [$time_local] '
@ -10,103 +8,114 @@ server {
'"$http_referer" "$http_user_agent" ' '"$http_referer" "$http_user_agent" '
'$request_time'; '$request_time';
# Updated log paths and format
access_log /var/log/nginx/deafgain-website/access.log matomo_tracking buffer=512k flush=1m;
error_log /var/log/nginx/deafgain-website/error.log error;
# Increased buffer sizes
large_client_header_buffers 8 32k;
client_header_buffer_size 32k;
client_max_body_size 10M;
client_body_buffer_size 128k;
# Security headers
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
add_header Strict-Transport-Security "max-age=31536000";
# Compression # Compression
gzip on; gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# API endpoint server {
location /api/contact { listen 804;
proxy_pass http://api:3000; server_name localhost;
proxy_http_version 1.1; root /usr/share/nginx/html;
proxy_set_header Host $host; index index.html;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # Log paths and format
proxy_set_header X-Forwarded-Proto $scheme;
access_log /var/log/nginx/deafgain-website/access.log matomo_tracking buffer=512k flush=1m; access_log /var/log/nginx/deafgain-website/access.log matomo_tracking buffer=512k flush=1m;
error_log /var/log/nginx/deafgain-website/error.log error; error_log /var/log/nginx/deafgain-website/error.log error;
# CORS headers # Increased buffer sizes
add_header 'Access-Control-Allow-Origin' '*'; large_client_header_buffers 8 32k;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; client_header_buffer_size 32k;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; client_max_body_size 10M;
client_body_buffer_size 128k;
# Handle OPTIONS method
if ($request_method = 'OPTIONS') { # Security headers
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
add_header Strict-Transport-Security "max-age=31536000";
# API endpoint
location /api/contact {
proxy_pass http://api:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
access_log /var/log/nginx/deafgain-website/access.log matomo_tracking buffer=512k flush=1m;
error_log /var/log/nginx/deafgain-website/error.log error;
# CORS headers
add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8'; # Handle OPTIONS method
add_header 'Content-Length' 0; if ($request_method = 'OPTIONS') {
return 204; add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
} }
}
location / { location / {
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html;
expires 1h; expires 1h;
add_header Cache-Control "public, no-transform"; add_header Cache-Control "public, no-transform";
}
# Video files handling
location /videos/ {
alias /usr/share/nginx/html/videos/;
add_header Cache-Control "public, no-transform";
types {
video/mp4 mp4;
} }
add_header Accept-Ranges bytes;
}
# Images handling # Video files handling
location /images/ { location /videos/ {
alias /usr/share/nginx/html/images/; alias /usr/share/nginx/html/videos/;
add_header Cache-Control "public, no-transform"; add_header Cache-Control "public, no-transform";
types { types {
image/png png; video/mp4 mp4;
image/jpeg jpg jpeg; }
image/svg+xml svg; add_header Accept-Ranges bytes;
} }
}
# Subtitles handling # Images handling
location /subtitles/ { location /images/ {
alias /usr/share/nginx/html/subtitles/; alias /usr/share/nginx/html/images/;
add_header Cache-Control "public, no-transform"; add_header Cache-Control "public, no-transform";
types { types {
text/vtt vtt; image/png png;
image/jpeg jpg jpeg;
image/svg+xml svg;
}
} }
}
# Transcriptions handling # Subtitles handling
location /transcriptions/ { location /subtitles/ {
alias /usr/share/nginx/html/transcriptions/; alias /usr/share/nginx/html/subtitles/;
add_header Cache-Control "public, no-transform"; add_header Cache-Control "public, no-transform";
types { types {
text/plain txt; text/vtt vtt;
}
} }
}
# Static asset caching # Transcriptions handling
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|vtt|txt)$ { location /transcriptions/ {
expires 30d; alias /usr/share/nginx/html/transcriptions/;
add_header Cache-Control "public, no-transform"; add_header Cache-Control "public, no-transform";
types {
text/plain txt;
}
}
# Static asset caching
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|vtt|txt)$ {
expires 30d;
add_header Cache-Control "public, no-transform";
}
} }
} }
events {
worker_connections 1024;
}