大网数据广告活动
服务器运维问答

Nginx reverse proxy is slow

· 52CE 我爱测

I have Nginx working as a reverse proxy for Apache, but it all websites take long time to load. Also I feel that Nginx doesn't work as expected. I'm sure that there is something wrong with virtual host configuration. The followin…

问题原文

原帖链接 · HuMaN-BiEnG · CC BY-SA 3.0

I have Nginx working as a reverse proxy for Apache, but it all websites take long time to load. Also I feel that Nginx doesn't work as expected.

I'm sure that there is something wrong with virtual host configuration. The following is virtual host configuration that I use:

server {
root   /home/username/public_html;
listen xx.xx.xx.xx:80;
server_name domain.com www.domain.com;
access_log  /dev/null;
error_log  /usr/local/nginx/logs/vhost-error_log warn;
index index.php index.html index.htm;

location / {

location ~.*.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|ttf|svg|eot)$ {
gzip_static on;
proxy_cache nginx-cache;
root   /home/username/public_html;
tcp_nodelay On;
tcp_nopush On;
access_log  /dev/null;
log_not_found Off;
expires 7d;
}

error_page 404 403 502 505 506 = @apachebackend;
add_header X-Cache "HIT from Backend";
proxy_pass   http://xx.xx.xx.xx:8080;
include /usr/local/nginx/conf/proxy.conf;
}

location @apachebackend {
internal;
proxy_pass   http://xx.xx.xx.xx:8080;
include /usr/local/nginx/conf/proxy.conf;
}

}

also the following are the contents of proxy.conf:

proxy_buffering Off;
proxy_cache_valid 404 3h;
proxy_cache_valid 500 502 504 406 3h;
proxy_cache_valid 200 6h;
proxy_buffers 100  128k;
proxy_busy_buffers_size 512k;
proxy_buffer_size 128k;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_cache nginx-cache;
proxy_cache_key "$host$request_uri";
proxy_ignore_headers Set-Cookie;
proxy_cache_min_uses 3;
proxy_max_temp_file_size 0;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 15m;
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
proxy_ignore_client_abort off;
proxy_intercept_errors off;
proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment;
proxy_cache_bypass $http_pragma $http_authorization;

Any help will be appreciated.

已采纳解答

原帖链接 · Anubioz · CC BY-SA 3.0

Try do do the following: remove proxy_cache nginx-cache;, remove proxy_buffering Off; and replace proxy.conf contents with the following values:

proxy_buffers           32 4m;
proxy_busy_buffers_size     25m;
proxy_buffer_size 512k;
proxy_ignore_headers "Cache-Control" "Expires";
proxy_max_temp_file_size 0;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size        1024m;
client_body_buffer_size     4m;
proxy_connect_timeout 300;
proxy_read_timeout 300;
proxy_send_timeout 300;
proxy_intercept_errors off;

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-08-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。