Skip to content

[Compose] Optimize large file uploads #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 98 additions & 82 deletions docker/compose/configs/nginx/nginx.conf.sample
Original file line number Diff line number Diff line change
@@ -1,108 +1,94 @@
# User and worker process configuration
user root;
# May be equal to `grep processor /proc/cpuinfo | wc -l`
worker_processes auto;
worker_cpu_affinity auto;

# PCRE JIT can speed up processing of regular expressions significantly.
pcre_jit on;

# error_log
# Error log configuration
error_log /var/log/nginx/error.log notice;

# Events configuration
events {
# Should be equal to `ulimit -n`
worker_connections 1024;

# Let each process accept multiple connections.
multi_accept on;

# Preferred connection method for newer linux versions.
use epoll;
worker_connections 1024; # Maximum number of connections per worker
multi_accept on; # Accept as many connections as possible per event
use epoll; # Use epoll for scalable I/O
}

# Stream configuration for TCP/UDP traffic
stream {
server {
listen 2222;
proxy_pass gitlab-shell:2222;
listen 2222; # Listen on TCP port 2222
proxy_pass gitlab-shell:2222; # Forward traffic to GitLab Shell on port 2222
}
}

# HTTP block configuration
http {
# Disables the “Server” response header
# Disable server version token in responses
server_tokens off;
charset utf-8;

# Sendfile copies data between one FD and other from within the kernel.
# More efficient than read() + write(), since the requires transferring
# data to and from the user space.
sendfile on;

# Tcp_nopush causes nginx to attempt to send its HTTP response head in one
# packet, instead of using partial frames. This is useful for prepending
# headers before calling sendfile, or for throughput optimization.
tcp_nopush on;
charset utf-8; # Set default charset to UTF-8

# Don't buffer data-sends (disable Nagle algorithm). Good for sending
# frequent small bursts of data in real time.
#
tcp_nodelay on;
# Enable file transfer optimization
sendfile on; # Send files directly from disk
tcp_nopush on; # Reduce network congestion
tcp_nodelay on; # Send packets immediately without delay

# http://nginx.org/en/docs/hash.html
# Mime types and default type
types_hash_max_size 4096;
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"';
# Enhanced log format for troubleshooting upstream issues
log_format debug_log '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'upstream_addr=$upstream_addr upstream_status=$upstream_status '
'request_time=$request_time upstream_response_time=$upstream_response_time';

# Logging Settings
access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/access.log debug_log;

# Gzip Settings
# Gzip compression settings
gzip on;
gzip_disable "msie6";

gzip_comp_level 6;
# gzip_comp_level 9;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
# gzip_http_version 1.1;
gzip_types text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss;

# Configure nginx to proxy large file requests

# nginx does not buffer client requests and does not buffer proxy server requests
# Proxy and buffering optimization
proxy_request_buffering off;
proxy_buffering off;

# Temporary storage path, ensure this path has enough space
client_body_temp_path /var/nginx/client_body_temp;
# Maximum size of temporary files
proxy_max_temp_file_size 150000M;

# Maximum size of client requests
client_max_body_size 0;

# Increase timeout settings to support large file transfers
client_body_timeout 300s;
client_header_timeout 300s;
send_timeout 300s;
keepalive_timeout 300s;
proxy_read_timeout 3600;
proxy_connect_timeout 300;
proxy_buffering on;
proxy_buffers 16 64k;
proxy_buffer_size 128k;
proxy_busy_buffers_size 256k;

client_body_temp_path /var/nginx/client_body_temp 1 2; # Recommend using SSD storage
proxy_max_temp_file_size 150000M; # Avoid large temporary files
client_max_body_size 0; # No limit for client request body size

# Global timeout settings (explicit units)
client_body_timeout 3600s;
client_header_timeout 3600s;
send_timeout 3600s;
keepalive_timeout 600s;
proxy_read_timeout 3600s;
proxy_connect_timeout 300s;
proxy_redirect off;
proxy_http_version 1.1;

# Connection upgrade mapping
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
default upgrade;
'' close;
}

# Main server configurations
server {
listen _SERVER_PORT;
server_name _SERVER_DOMAIN;

# Default route
location / {
proxy_pass http://csghub-portal:8090;
proxy_set_header X-Forwarded-Proto $scheme;
Expand All @@ -111,6 +97,7 @@ http {
proxy_set_header Host $host;
}

# API route
location /api/ {
proxy_pass http://csghub-server:8080/api/;
proxy_set_header Host $host;
Expand All @@ -120,6 +107,7 @@ http {
proxy_set_header X-Forwarded-Proto $scheme;
}

# HF route
location /hf/ {
proxy_pass http://csghub-server:8080/hf/;
proxy_set_header Host $host;
Expand All @@ -129,6 +117,7 @@ http {
proxy_set_header X-Forwarded-Proto $scheme;
}

# Temporal UI route with basic auth
location /temporal-ui/ {
auth_basic "Please login with your account:";
auth_basic_user_file /etc/nginx/ssl/.htpasswd;
Expand All @@ -139,8 +128,9 @@ http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

# Endpoint route
location /endpoint/ {
proxy_pass http://csghub-proxy:8083;
proxy_set_header Host $host;
Expand All @@ -150,43 +140,47 @@ http {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_cookie_flags ~ nosecure samesite=lax;
proxy_cookie_flags ~ nosecure samesite=lax; # Set secure and samesite cookies
}

# Git specific route
location ~* \.git(/.*)?$ {
proxy_pass http://csghub-server:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
}

# Custom error page handling for 50x errors
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
root /usr/share/nginx/html;
}
}

# Docker registry service
server {
listen 5000;
server_name _SERVER_DOMAIN;

client_max_body_size 0;
client_max_body_size 0; # Allow unlimited body size
chunked_transfer_encoding on;

location /v2/ {
if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$" ) {
return 404;
if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$") {
return 404; # Block unsupported Docker clients
}

proxy_pass http://registry:5000;
proxy_set_header Host $http_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_read_timeout 900;
proxy_pass http://registry:5000;
proxy_set_header Host $http_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_read_timeout 900;
}
}

# Casdoor service configuration
server {
listen 8000;
server_name _SERVER_DOMAIN;
Expand All @@ -206,54 +200,76 @@ http {
}
}

# MinIO service configuration
server {
listen 9000;
server_name _SERVER_DOMAIN;

ignore_invalid_headers off;
client_max_body_size 0;

client_header_timeout 7200s;
client_body_timeout 7200s;
proxy_read_timeout 7200s;
proxy_send_timeout 7200s;

proxy_request_buffering on;
proxy_buffering on;
proxy_buffers 32 256k;
proxy_buffer_size 512k;
proxy_busy_buffers_size 1m;

location / {
proxy_set_header Host $http_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 300;
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
proxy_connect_timeout 300s;
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;

proxy_pass http://minio:9000;
}
}
}

# More MinIO server configuration
server {
listen 9001;
server_name _SERVER_DOMAIN;

ignore_invalid_headers off;
client_max_body_size 0;

client_header_timeout 7200s;
client_body_timeout 7200s;
proxy_read_timeout 7200s;
proxy_send_timeout 7200s;

proxy_request_buffering on;
proxy_buffering on;
proxy_buffers 32 256k;
proxy_buffer_size 512k;
proxy_busy_buffers_size 1m;

location / {
proxy_set_header Host $http_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 300;
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
proxy_connect_timeout 300s;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
chunked_transfer_encoding off;

proxy_pass http://minio:9001;
}
}
}

# Dynamic HTTP routing for apps
server {
listen 80;
server_name *._SPACE_APP_NAMESPACE._SPACE_APP_INTERNAL_DOMAIN;
Expand All @@ -274,4 +290,4 @@ http {
root /usr/share/nginx/html;
}
}
}
}
Loading