Files
dex-ui-vue/nginx.conf.template
2025-07-17 13:00:20 +02:00

89 lines
2.7 KiB
Plaintext

# Main nginx configuration
worker_processes auto;
error_log /dev/stderr warn;
pid /tmp/nginx.pid; # Use writable location for PID
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
access_log /dev/stdout;
client_body_temp_path /tmp/client_temp;
proxy_temp_path /tmp/proxy_temp;
fastcgi_temp_path /tmp/fastcgi_temp;
uwsgi_temp_path /tmp/uwsgi_temp;
scgi_temp_path /tmp/scgi_temp;
absolute_redirect off;
map $http_origin $cors_origin {
default "";
"~*" $http_origin;
}
resolver 127.0.0.11 valid=10s ipv6=off;
upstream backend {
server ${API_HOST}:8080;
}
server {
listen 7070;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# Handle client-side routing
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
# Security headers
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "DENY";
add_header Referrer-Policy "strict-origin-when-cross-origin";
}
# Serve config.js from the writable location
location = /config.js {
alias /runtime-config/config.js;
add_header Cache-Control "no-store, no-cache, must-revalidate";
access_log off;
}
location /api/ {
proxy_pass http://backend:8080/;
# Headers for both simple and preflight requests
add_header 'Access-Control-Allow-Origin' '$http_origin' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type' always;
add_header 'Access-Control-Expose-Headers' 'Authorization' always;
# Handle OPTIONS directly
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
}
}