mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-10-28 23:57:58 +09:00
Stock nginx (1.18-1.24 on Debian/Ubuntu) has no `.mjs` entry in mime.types, so the runtime-extension vendor shims the import map points at came back as application/octet-stream. Browsers refuse to execute an ES module with that type, so every runtime-loaded extension (WordPress, Git, Mail, Fail2ban, ...) failed on fresh installs with "Failed to fetch dynamically imported module: blob:..." (Chrome) or "'application/octet-stream' is not a valid JavaScript MIME type" (Safari). Add a location block to the shipped vhosts (and the container frontend config) that forces text/javascript for /serverkit-vendor/*.mjs. The regex is anchored to that folder: a bare `\.mjs$` would also capture the /api/v1/plugins/<slug>/assets/dist/index.mjs route and 404 every bundle. update.sh already re-copies these vhosts, so existing installs pick it up on their next update. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NWc84WDsWR7M55Mn7qtpie
157 lines
5.4 KiB
Nginx Configuration File
157 lines
5.4 KiB
Nginx Configuration File
# ServerKit Frontend Nginx Configuration
|
|
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# Gzip compression
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 1024;
|
|
gzip_proxied any;
|
|
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml;
|
|
|
|
# Security headers
|
|
add_header X-Frame-Options "DENY" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
# SPA routing - serve index.html for all routes
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# Proxy API requests to the backend, which runs on the HOST (systemd), not
|
|
# in Docker. `backend` resolves to the host via the compose `extra_hosts:
|
|
# ["backend:host-gateway"]` alias (see docker-compose.yml).
|
|
location /api {
|
|
proxy_pass http://backend:5000;
|
|
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;
|
|
|
|
# Timeout settings
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
}
|
|
|
|
# WebSocket support for socket.io (running on host, not in Docker)
|
|
location /socket.io {
|
|
proxy_pass http://backend:5000;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
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;
|
|
|
|
# WebSocket specific timeouts
|
|
proxy_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
}
|
|
|
|
# Runtime-extension vendor shims (/serverkit-vendor/*.mjs). nginx builds
|
|
# without an `.mjs` MIME entry serve application/octet-stream, which the
|
|
# browser refuses to import as an ES module and every runtime-loaded
|
|
# extension fails with "Failed to fetch dynamically imported module".
|
|
# Force the type; the shims are not hashed, so they must revalidate.
|
|
# Anchored to the shim folder: a bare `\.mjs$` regex would also capture
|
|
# /api/v1/plugins/<slug>/assets/dist/index.mjs (regex locations beat the
|
|
# /api prefix block) and 404 every extension bundle instead.
|
|
location ~* ^/serverkit-vendor/.+\.mjs$ {
|
|
types { }
|
|
default_type text/javascript;
|
|
try_files $uri =404;
|
|
expires -1;
|
|
}
|
|
|
|
# Cache static assets
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
}
|
|
|
|
# HTTPS server - DISABLED for development (requires SSL certificates)
|
|
# To enable: mount SSL certs to /etc/nginx/ssl/ and uncomment this block
|
|
# server {
|
|
# listen 443 ssl http2;
|
|
# server_name localhost;
|
|
# root /usr/share/nginx/html;
|
|
# index index.html;
|
|
#
|
|
# # SSL Configuration
|
|
# ssl_certificate /etc/nginx/ssl/fullchain.pem;
|
|
# ssl_certificate_key /etc/nginx/ssl/privkey.pem;
|
|
# ssl_session_timeout 1d;
|
|
# ssl_session_cache shared:SSL:50m;
|
|
# ssl_session_tickets off;
|
|
#
|
|
# # Modern SSL configuration
|
|
# ssl_protocols TLSv1.2 TLSv1.3;
|
|
# ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
|
|
# ssl_prefer_server_ciphers off;
|
|
#
|
|
# # HSTS
|
|
# add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
|
|
#
|
|
# # Security headers
|
|
# add_header X-Frame-Options "DENY" always;
|
|
# add_header X-Content-Type-Options "nosniff" always;
|
|
# add_header X-XSS-Protection "1; mode=block" always;
|
|
# add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
#
|
|
# # Gzip compression
|
|
# gzip on;
|
|
# gzip_vary on;
|
|
# gzip_min_length 1024;
|
|
# gzip_proxied any;
|
|
# gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml;
|
|
#
|
|
# # SPA routing
|
|
# location / {
|
|
# try_files $uri $uri/ /index.html;
|
|
# }
|
|
#
|
|
# # API proxy
|
|
# location /api {
|
|
# proxy_pass http://backend:5000;
|
|
# 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;
|
|
# proxy_connect_timeout 60s;
|
|
# proxy_send_timeout 60s;
|
|
# proxy_read_timeout 60s;
|
|
# }
|
|
#
|
|
# # WebSocket proxy
|
|
# location /socket.io {
|
|
# proxy_pass http://backend:5000;
|
|
# proxy_http_version 1.1;
|
|
# proxy_set_header Upgrade $http_upgrade;
|
|
# proxy_set_header Connection "upgrade";
|
|
# 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;
|
|
# proxy_connect_timeout 7d;
|
|
# proxy_send_timeout 7d;
|
|
# proxy_read_timeout 7d;
|
|
# }
|
|
#
|
|
# # Cache static assets
|
|
# location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
# expires 1y;
|
|
# add_header Cache-Control "public, immutable";
|
|
# }
|
|
# }
|