| 1 | user nginx; |
| 2 | worker_processes auto; |
| 3 | error_log /var/log/nginx/error.log warn; |
| 4 | pid /var/run/nginx.pid; |
| 5 | |
| 6 | events { |
| 7 | worker_connections 1024; |
| 8 | } |
| 9 | |
| 10 | http { |
| 11 | include /etc/nginx/mime.types; |
| 12 | default_type application/octet-stream; |
| 13 | |
| 14 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
| 15 | '$status $body_bytes_sent "$http_referer" ' |
| 16 | '"$http_user_agent" "$http_x_forwarded_for"'; |
| 17 | |
| 18 | access_log /var/log/nginx/access.log main; |
| 19 | |
| 20 | sendfile on; |
| 21 | tcp_nopush on; |
| 22 | tcp_nodelay on; |
| 23 | keepalive_timeout 65; |
| 24 | types_hash_max_size 2048; |
| 25 | |
| 26 | gzip on; |
| 27 | gzip_vary on; |
| 28 | gzip_proxied any; |
| 29 | gzip_comp_level 6; |
| 30 | gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml; |
| 31 | |
| 32 | client_max_body_size 50m; |
| 33 | |
| 34 | map $http_origin $cors_origin { |
| 35 | default ""; |
| 36 | "~^https?://(.*\.)?(dev\.)?aitoearn\.ai$" $http_origin; |
| 37 | "~^https?://localhost(:[0-9]+)?$" $http_origin; |
| 38 | "~^https?://127\.0\.0\.1(:[0-9]+)?$" $http_origin; |
| 39 | "~^https?://0\.0\.0\.0(:[0-9]+)?$" $http_origin; |
| 40 | } |
| 41 | |
| 42 | proxy_set_header Host $proxy_host; |
| 43 | proxy_set_header X-Real-IP $remote_addr; |
| 44 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 45 | proxy_set_header X-Forwarded-Proto $scheme; |
| 46 | proxy_set_header X-Forwarded-Host $host; |
| 47 | proxy_http_version 1.1; |
| 48 | |
| 49 | # Hide backend CORS headers, managed by nginx |
| 50 | proxy_hide_header Access-Control-Allow-Origin; |
| 51 | proxy_hide_header Access-Control-Allow-Methods; |
| 52 | proxy_hide_header Access-Control-Allow-Headers; |
| 53 | proxy_hide_header Access-Control-Allow-Credentials; |
| 54 | proxy_hide_header Access-Control-Max-Age; |
| 55 | |
| 56 | proxy_connect_timeout 120s; |
| 57 | proxy_send_timeout 60s; |
| 58 | proxy_read_timeout 86400s; |
| 59 | |
| 60 | add_header Access-Control-Allow-Origin $cors_origin always; |
| 61 | add_header Access-Control-Allow-Methods "GET, HEAD, POST, PUT, DELETE, PATCH, OPTIONS" always; |
| 62 | add_header Access-Control-Allow-Headers "Accept, Accept-Encoding, Accept-Language, Authorization, Cache-Control, Content-Type, Cookie, DNT, Origin, Pragma, Referer, User-Agent, X-Requested-With, X-Request-ID, X-CSRF-Token, X-Auth-Token, X-HTTP-Method-Override, Next-Router-Prefetch, Next-Router-State-Tree, Next-Url, RSC, Sec-CH-UA, Sec-CH-UA-Mobile, Sec-CH-UA-Platform, Sec-Fetch-Dest, Sec-Fetch-Mode, Sec-Fetch-Site, Priority, If-None-Match, If-Modified-Since" always; |
| 63 | add_header Access-Control-Allow-Credentials true always; |
| 64 | add_header Access-Control-Max-Age 86400 always; |
| 65 | |
| 66 | server { |
| 67 | listen 80; |
| 68 | listen [::]:80; |
| 69 | server_name _; |
| 70 | |
| 71 | location = /_nhealth { |
| 72 | access_log off; |
| 73 | default_type text/plain; |
| 74 | return 200 "healthy\n"; |
| 75 | } |
| 76 | |
| 77 | if ($request_method = 'OPTIONS') { |
| 78 | return 204; |
| 79 | } |
| 80 | |
| 81 | location /api/ai/ { |
| 82 | rewrite ^/api/(.*)$ /$1 break; |
| 83 | proxy_pass http://aitoearn-ai:3010; |
| 84 | } |
| 85 | |
| 86 | location /api/agent/ { |
| 87 | rewrite ^/api/(.*)$ /$1 break; |
| 88 | proxy_pass http://aitoearn-ai:3010; |
| 89 | } |
| 90 | |
| 91 | location /api/ { |
| 92 | rewrite ^/api/(.*)$ /$1 break; |
| 93 | proxy_pass http://aitoearn-server:3002; |
| 94 | } |
| 95 | |
| 96 | location /oss/ { |
| 97 | proxy_pass http://aitoearn-rustfs:9000/aitoearn/; |
| 98 | } |
| 99 | |
| 100 | location / { |
| 101 | proxy_pass http://aitoearn-web:3000; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | # S3 代理:浏览器通过此端口上传文件到 rustfs |
| 106 | server { |
| 107 | listen 9000; |
| 108 | listen [::]:9000; |
| 109 | server_name _; |
| 110 | |
| 111 | client_max_body_size 500m; |
| 112 | |
| 113 | add_header Access-Control-Allow-Origin * always; |
| 114 | add_header Access-Control-Allow-Methods "GET, HEAD, PUT, POST, DELETE, OPTIONS" always; |
| 115 | add_header Access-Control-Allow-Headers * always; |
| 116 | add_header Access-Control-Expose-Headers "ETag" always; |
| 117 | add_header Access-Control-Max-Age 86400 always; |
| 118 | |
| 119 | if ($request_method = 'OPTIONS') { |
| 120 | return 204; |
| 121 | } |
| 122 | |
| 123 | location / { |
| 124 | proxy_pass http://aitoearn-rustfs:9000; |
| 125 | proxy_set_header Host $http_host; |
| 126 | proxy_http_version 1.1; |
| 127 | proxy_connect_timeout 120s; |
| 128 | proxy_send_timeout 120s; |
| 129 | proxy_read_timeout 120s; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 |