我有Nginx作为Apache的反向代理工作,但所有网站都需要很长时间才能加载。 另外我觉得Nginx并没有像预期的那样工作。
我确定虚拟主机configuration有问题。 以下是我使用的虚拟主机configuration:
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; } }
以下是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;
任何帮助将不胜感激。
尝试做到以下几点:删除proxy_cache nginx-cache; ,删除proxy_buffering Off; 并使用以下值replaceproxy.conf内容:
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;