From 893c0d0334c4289c45be63e5eb77bc98a00fba40 Mon Sep 17 00:00:00 2001 From: ganweichong Date: Sun, 12 Oct 2025 18:32:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx.conf | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 nginx.conf diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..b9405da --- /dev/null +++ b/nginx.conf @@ -0,0 +1,98 @@ +server { + listen 80; + server_name _; + client_max_body_size 5000m; + # 启用gzip压缩 + gzip on; + gzip_min_length 2k; + gzip_buffers 4 16k; + gzip_http_version 1.1; + gzip_comp_level 2; + gzip_types + # text/html is always compressed by HttpGzipModule + text/css + text/javascript + text/xml + text/plain + text/x-component + application/javascript + application/x-javascript + application/json + application/xml + application/rss+xml + font/truetype + font/opentype + application/vnd.ms-fontobject + application/x-httpd-php + image/jpeg + image/gif + image/png + image/svg+xml; + gzip_vary on; + + # 前端静态页面 + root /usr/share/nginx/html; + index index.html; + + # 处理 Vue Router 的 history 模式 + location / { + try_files $uri $uri/ /index.html; + } + + # 前端路径修改 + location /selenium_web/ { + proxy_pass http://selenium-vue-container:80/; + + 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; + } + + # 后端 API 代理 + location /selenium_api/ { + proxy_pass http://selenium-django-container:8000/; + + # 基本身份头 + 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; + + # SSE 关键配置 + proxy_cache off; # 禁用缓存 + proxy_buffering off; # 禁用缓冲(关键!) + proxy_http_version 1.1; # 使用 HTTP/1.1 + proxy_set_header Connection ''; # 清除 Connection 头 + + # 超时设置(根据需要调整) + proxy_read_timeout 3600s; # 读取超时(1小时,根据实际需求调整) + proxy_send_timeout 3600s; # 发送超时 + + # 可选:设置正确的 Content-Type(如果后端未正确设置) + # proxy_hide_header Content-Type; + add_header Content-Type "text/event-stream"; + + # 可选:允许跨域(如果前端和后端域名不同) + add_header Access-Control-Allow-Origin *; + add_header Access-Control-Allow-Credentials true; + } + # 后端爬虫 API 代理 + location /selenium_crawl_api/ { + proxy_pass http://selenium-crawl-container:5000/; + + 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; + } + + # 静态文件 + location /static1/ { + alias /app/static/; + } + # 媒体文件 + location /media1/ { + alias /app/media/; + } +} \ No newline at end of file