openpetswithchatandmcp/website/nginx.conf
OpenPets Dev 65ac83849e Add 'website/' from commit '966aea480ffe1c340553aa878def30131d2af827'
git-subtree-dir: website
git-subtree-mainline: 8d3849caea
git-subtree-split: 966aea480f
2026-06-17 20:48:39 +00:00

153 lines
4.9 KiB
Nginx Configuration File
Executable file

# WebSocket connection upgrade map
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# Overleaf backend upstream
upstream overleaf {
server overleaf:80;
}
# HTTP server
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# Enable gzip compression
gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json;
gzip_disable "MSIE [1-6]\.";
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "upgrade-insecure-requests" always;
# Upstream proxy settings for Overleaf
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_redirect off;
client_max_body_size 50m;
# Proxy Overleaf auth endpoints
location = /login {
proxy_pass http://overleaf;
}
location = /logout {
proxy_pass http://overleaf;
}
# Proxy Overleaf API endpoints
location ^~ /api/ {
proxy_pass http://overleaf;
}
location ^~ /user/ {
proxy_pass http://overleaf;
}
# Private endpoints need Basic Auth - MUST come before general /project/ location
location ~ ^/project/[^/]+/join$ {
proxy_pass http://overleaf;
proxy_set_header Authorization "Basic YXBpdXNlcjphcGlwYXNz";
proxy_pass_request_headers on;
proxy_set_header Cookie $http_cookie;
}
location ~ ^/project/[^/]+/doc/ {
proxy_pass http://overleaf;
proxy_set_header Authorization "Basic YXBpdXNlcjphcGlwYXNz";
proxy_pass_request_headers on;
proxy_set_header Cookie $http_cookie;
}
location ~ ^/project/[^/]+/compile {
proxy_pass http://overleaf;
proxy_pass_request_headers on;
proxy_set_header Cookie $http_cookie;
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;
}
location ~ ^/project/[^/]+/output/ {
proxy_pass http://overleaf;
proxy_pass_request_headers on;
proxy_set_header Cookie $http_cookie;
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;
}
location ^~ /internal/ {
proxy_pass http://overleaf;
proxy_set_header Authorization "Basic YXBpdXNlcjphcGlwYXNz";
proxy_pass_request_headers on;
proxy_set_header Cookie $http_cookie;
}
# General project endpoints (without ^~ so regex patterns above are checked first)
location /project/ {
proxy_pass http://overleaf;
proxy_pass_request_headers on;
proxy_set_header Cookie $http_cookie;
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;
}
location /Project/ {
proxy_pass http://overleaf;
}
# Block direct access to Overleaf's project list UI to avoid confusion
location = /project {
return 302 /;
}
# WebSocket support for real-time collaboration
location /socket.io/ {
proxy_pass http://overleaf;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $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_set_header Cookie $http_cookie;
proxy_read_timeout 86400;
proxy_buffering off;
}
# SPA fallback - serve index.html for all non-API routes
location / {
try_files $uri $uri/ /index.html;
}
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# Disable cache for index.html
location = /index.html {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
}
# Health check endpoint
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
}