Files
Warracker/nginx.conf
sassanix e045aae208 Vendor, Date Format, Added security
Refer to changelogs
2025-05-04 13:02:51 -03:00

106 lines
3.9 KiB
Nginx Configuration File

server {
listen 80;
listen [::]:80;
server_name localhost;
# Point root to the frontend directory where static assets reside
root /d/Project/warracker/Warracker Beta/frontend;
index index.html;
# Enable detailed error logging
error_log /var/log/nginx/error.log debug;
access_log /var/log/nginx/access.log;
# Global settings
gzip on;
gzip_types text/plain text/css application/javascript application/json;
client_max_body_size 32M;
# Add CORS headers globally
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
# MIME types - fixed duplicate js entry
types {
text/html html htm shtml;
text/css css;
application/javascript js;
image/png png;
image/jpeg jpg jpeg;
image/gif gif;
image/svg+xml svg svgz;
application/pdf pdf;
image/x-icon ico;
}
# API requests - proxy to backend (fixed upstream host)
location /api/ {
proxy_pass http://127.0.0.1:5000/;
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;
client_max_body_size 32M;
# Pass Authorization header to backend
proxy_set_header Authorization $http_authorization;
# Add debug headers to see what's happening
add_header X-Debug-Message "API request proxied to backend" always;
# CORS for API
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
# CORS preflight
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
add_header 'Access-Control-Max-Age' 1728000 always;
add_header 'Content-Type' 'text/plain charset=UTF-8' always;
add_header 'Content-Length' 0 always;
return 204;
}
}
# Uploads - serve files from uploads directory
location /uploads/ {
return 403 "Access forbidden";
}
# HTML files - ensure proper content type
location ~ \.html$ {
add_header Content-Type "text/html; charset=utf-8";
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# Favicon - specific handling
location = /favicon.ico {
log_not_found off;
access_log off;
try_files $uri =404;
expires 7d;
add_header Cache-Control "public, max-age=604800";
}
# Static assets (CSS, JS, images)
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg)$ {
try_files $uri =404;
expires 7d;
add_header Cache-Control "public, max-age=604800";
}
# Test uploads path
location = /test-uploads {
add_header Content-Type text/plain;
return 200 "Uploads directory exists: $document_root\n";
}
# Default location
location / {
try_files $uri $uri/ /index.html;
}
}