Files
org-social-host/nginx.conf
Andros Fenollosa f3631a1d75 feat: Add redirect from /username/ to /username/social.org
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>
2025-11-23 11:19:34 +01:00

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;
}