开启反向代理后,代理网址访问特别慢
本帖最后由 宝塔用户_nwkonz 于 2025-7-31 08:24 编辑为了能快速了解并处理您的问题,请提供以下基础信息:面板、插件版本:V11.NGINX:1.26.1
系统版本:CentOS 7
问题描述:开启反向代理后,访问一卡一卡的。
相关截图(日志、错误):反向代理配置
#PROXY-START/seeyon
location ^~ / {
# 基本代理设置
proxy_pass http://172.16.1.251:8888;
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_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# 减少超时时间以提高性能
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
# 添加重定向修改
proxy_redirect off;
# 启用压缩传输,删除之前禁用压缩的设置
# 设置接受所有内容类型
proxy_set_header Accept "*/*";
# 为所有JavaScript文件设置正确的MIME类型
if ($request_uri ~* \.(js|jsx)($|\?)) {
add_header Content-Type application/javascript;
}
# 为动态生成的JavaScript内容设置MIME类型
if ($request_uri ~* (vPortalData|jsData)) {
add_header Content-Type application/javascript;
}
# 创建强制cookie,帮助保持会话
add_header Set-Cookie "JSESSIONID=$upstream_http_set_cookie;Path=/;HttpOnly;Secure";
}
# 添加静态资源处理
location ~* /.*\.(gif|jpg|jpeg|png|css|ico|svg|woff|woff2|ttf|eot)$ {
proxy_pass http://172.16.1.251:8888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
expires 30d;
# 减少静态资源的超时时间
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
# 缓存静态资源
proxy_cache seeyon_cache;
proxy_cache_valid 200 30d;
proxy_cache_valid 404 1m;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_lock on;
# 优化gzip配置
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 4;
gzip_types text/plain application/javascript text/css application/xml application/x-javascript text/javascript application/x-httpd-php image/svg+xml;
gzip_vary on;
gzip_disable "MSIE \.";
# 优化缓冲区设置
proxy_buffering on;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
}
# 专门针对JavaScript文件优化 - 解决JS文件加载慢问题
location ^~ /seeyon/.*\.js {
proxy_pass http://172.16.1.251:8888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 针对JS文件的强力缓存优化
expires 7d; # 缓存7天
add_header Cache-Control "public, max-age=604800, immutable";
# 性能优化
proxy_buffering on;
proxy_connect_timeout 60s;
proxy_read_timeout 90s; # 针对大型JS文件的较长读取时间
proxy_send_timeout 60s;
# 压缩优化
gzip on;
gzip_min_length 1k;
gzip_comp_level 7; # 更高级别的压缩
gzip_types application/javascript application/x-javascript text/javascript;
gzip_vary on;
add_header Content-Type application/javascript;
add_header Link "</seeyon/main.js>; rel=preload; as=script";
}
# 特别针对debug.js文件的优化
location ^~ /seeyon/.*debug\.js {
proxy_pass http://172.16.1.251:8888;
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_read_timeout 30s;
# 设置正确的内容类型
add_header Content-Type application/javascript;
# 压缩优化
gzip on;
gzip_comp_level 9; # 最高压缩级别
# 针对JS文件的强力缓存优化
expires 1d; # 缓存1天
add_header Cache-Control "public, max-age=86400";
}
# AJAX请求(.do文件)的专门优化 - 针对ajax.do等请求
location ^~ /seeyon/.*\.do {
proxy_pass http://172.16.1.251:8888;
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_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
# 防止缓存动态内容
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
expires -1;
# AJAX请求优化
proxy_connect_timeout 5s; # 快速连接
proxy_read_timeout 15s; # 降低超时时间,避免长时间等待
proxy_send_timeout 5s;
# 针对AJAX请求的缓冲优化
proxy_buffering on;
proxy_buffers 8 32k; # 更多但更小的缓冲区
proxy_buffer_size 32k;
}
# 同样处理portalController.do请求
location ~* /seeyon/portal/portalController.do {
proxy_pass http://172.16.1.251:8888;
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_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
add_header Content-Type application/javascript;
# 减少超时时间
proxy_connect_timeout 30s;
proxy_read_timeout 30s;
proxy_send_timeout 30s;
}
location ^~ /seeyon/collaboration/ {
proxy_pass http://172.16.1.251:8888;
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_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
# 专门针对协作请求的优化
proxy_connect_timeout 10s; # 快速连接
proxy_read_timeout 180s; # 增加读取超时时间
proxy_send_timeout 60s;
# 缓冲区优化
proxy_buffers 16 32k; # 增加缓冲区数量
proxy_busy_buffers_size 128k;
# 禁止缓存动态内容但启用转换
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
# 启用压缩
gzip on;
gzip_min_length 1k;
gzip_comp_level 6;
gzip_vary on;
}
#PROXY-END/
有人解答吗
页:
[1]