Skip to content
Snippets Groups Projects
nginx.conf 4.26 KiB
Newer Older
  • Learn to ignore specific revisions
  • Matthias Feyll's avatar
    Matthias Feyll committed
    worker_processes  1;
    
    events {
        worker_connections  1024;
    
    Matthias Feyll's avatar
    Matthias Feyll committed
    }
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
    
        log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log /var/log/nginx/access.log main buffer=16k;
    
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_tokens off;
    
        # Buffer size settings
        client_body_buffer_size 10K;
    
        client_header_buffer_size 8k;
    
        large_client_header_buffers 4 8k;
    
    
        # File descriptor cache
        open_file_cache max=2000 inactive=20s;
        open_file_cache_valid 60s;
        open_file_cache_min_uses 5;
        open_file_cache_errors off;
    
        # Compression settings
        gzip on;
        gzip_comp_level 6;
        gzip_min_length 256;
        gzip_proxied any;
        gzip_vary on;
        gzip_types
            application/javascript
            application/json
            application/x-javascript
            application/xml
            text/css
            text/javascript
            text/plain
            text/xml
            text/html
            application/x-font-ttf
            font/opentype
            application/vnd.ms-fontobject
            image/svg+xml;
    
    Matthias Feyll's avatar
    Matthias Feyll committed
    
        resolver 127.0.0.11 ipv6=off;
    
        server {
            listen       80;
            server_name  localhost;
    
            location ^~ /api/ {
                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 timeouts
                proxy_connect_timeout 60s;
                proxy_send_timeout 60s;
                proxy_read_timeout 60s;
                
                # Proxy buffering
                proxy_buffering on;
                proxy_buffer_size 4k;
                proxy_buffers 8 16k;
    
    Matthias Feyll's avatar
    Matthias Feyll committed
                
                # CORS headers
                add_header 'Access-Control-Allow-Origin' '*' always;
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
                add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
                add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
                
                if ($request_method = 'OPTIONS') {
                    add_header 'Access-Control-Allow-Origin' '*';
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                    add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                    add_header 'Access-Control-Max-Age' 1728000;
                    add_header 'Content-Type' 'text/plain; charset=utf-8';
                    add_header 'Content-Length' 0;
                    return 204;
                }
    
                # Remove /api prefix when proxying
                rewrite ^/api/(.*) /$1 break;
                proxy_pass http://clab-gosdn_csbi_arista_base-gosdn:8080;
            }
    
            location / {
                root   /usr/share/nginx/html;
                index  index.html;
                try_files $uri $uri/ /index.html;
            }
    
    
    
            # Static asset handling with improved caching
            location ~* \.(js|css|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|otf|eot)$ {
    
    Matthias Feyll's avatar
    Matthias Feyll committed
                root /usr/share/nginx/html;
                expires 30d;
    
                add_header Cache-Control "public, no-transform";
                add_header 'Access-Control-Allow-Origin' '*' always;
                
                # Enable compression for these files
                gzip_static on;  # Serve pre-compressed files if available
                
                # Disable access logs for static files
                access_log off;
    
    Matthias Feyll's avatar
    Matthias Feyll committed
            }
        }
    
    
    
    
        # HTTPS server
        #
        #server {
        #    listen       443 ssl;
        #    server_name  localhost;
    
        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;
    
        #    ssl_session_cache    shared:SSL:1m;
        #    ssl_session_timeout  5m;
    
        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers  on;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    }