mirror of
https://github.com/tanrax/org-social-host
synced 2026-01-08 06:13:33 +01:00
This makes URLs shorter and more user-friendly. Example: - https://host.org-social.org/andros/ → https://host.org-social.org/andros/social.org Implements 301 redirect for SEO compatibility. Signed-off-by: Andros Fenollosa <hi@andros.dev>
102 lines
2.6 KiB
Nginx Configuration File
102 lines
2.6 KiB
Nginx Configuration File
events {
|
|
worker_connections 1024;
|
|
}
|
|
|
|
http {
|
|
include /etc/nginx/mime.types;
|
|
default_type application/octet-stream;
|
|
|
|
upstream django_app {
|
|
server django:8000;
|
|
}
|
|
|
|
server {
|
|
listen 80;
|
|
server_name _;
|
|
|
|
# Security headers
|
|
add_header X-Frame-Options DENY;
|
|
add_header X-Content-Type-Options nosniff;
|
|
add_header X-XSS-Protection "1; mode=block";
|
|
|
|
# Proxy settings
|
|
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;
|
|
|
|
# Timeouts
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
|
|
# Serve static files (CSS, JS, images)
|
|
location /static/ {
|
|
alias /app/staticfiles/;
|
|
expires 30d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# Redirect /username/ to /username/social.org
|
|
location ~ ^/([a-zA-Z0-9_-]+)/$ {
|
|
return 301 $scheme://$host/$1/social.org;
|
|
}
|
|
|
|
# Serve static files directly (social.org files)
|
|
location ~ ^/[a-zA-Z0-9_-]+/social\.org$ {
|
|
# Try to serve from storage first, fallback to Django
|
|
root /app;
|
|
try_files $uri @django;
|
|
|
|
# Cache control for social.org files
|
|
add_header Cache-Control "public, max-age=60";
|
|
add_header Content-Type "text/plain; charset=utf-8";
|
|
}
|
|
|
|
# Main location (API endpoints)
|
|
location / {
|
|
proxy_pass http://django_app;
|
|
}
|
|
|
|
# Django fallback for file serving
|
|
location @django {
|
|
proxy_pass http://django_app;
|
|
}
|
|
|
|
# Health check endpoint
|
|
location /nginx-health {
|
|
access_log off;
|
|
return 200 "healthy\n";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
}
|
|
|
|
# Basic Nginx settings
|
|
sendfile on;
|
|
tcp_nopush on;
|
|
tcp_nodelay on;
|
|
keepalive_timeout 65;
|
|
types_hash_max_size 2048;
|
|
client_max_body_size 10M; # Allow uploads up to 10MB
|
|
|
|
# Logging
|
|
access_log /var/log/nginx/access.log;
|
|
error_log /var/log/nginx/error.log;
|
|
|
|
# GZIP compression
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 1024;
|
|
gzip_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_types
|
|
text/plain
|
|
text/css
|
|
text/xml
|
|
text/javascript
|
|
application/json
|
|
application/javascript
|
|
application/xml+rss
|
|
application/atom+xml;
|
|
}
|