Nginx提供文件的速度非常慢
我发现Nginx提供文件的速度非常慢。最终,我的应用程序加载速度很慢,然而,为了缩小问题的范围,我将生成的所有HTML保存到一个文件中,并一直使用Apache的基准测试来提取该HTML文件。这就是ab的平均运行情况:Nginx提供文件的速度非常慢,nginx,Nginx,我发现Nginx提供文件的速度非常慢。最终,我的应用程序加载速度很慢,然而,为了缩小问题的范围,我将生成的所有HTML保存到一个文件中,并一直使用Apache的基准测试来提取该HTML文件。这就是ab的平均运行情况: debian@localhost:/var/www/resources/laravel$ ab -n 5 -H "Accept-Encoding: gzip,deflate" http://lnp2.moveyourmountain.org/test1.html | grep -A
debian@localhost:/var/www/resources/laravel$ ab -n 5 -H "Accept-Encoding: gzip,deflate" http://lnp2.moveyourmountain.org/test1.html | grep -A 5 Connection
Connection Times (ms)
min mean[+/-sd] median max
Connect: 74 101 32.4 101 152
Processing: 1556 2315 431.6 2484 2622
Waiting: 74 79 7.2 77 91
Total: 1630 2416 450.1 2579 2774
所以,这就是为什么我认为这是Nginx的一个问题。我不完全确定要发布什么配置,所以我想我将发布nginx.conf和我的站点启用配置
nginx.conf
user www-data;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$http_x_forwarded_proto -- $remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" - $request_time';
access_log /var/log/nginx/access.log main;
#sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
gzip_comp_level 5;
# gzip_proxied any;
# gzip_vary on;
# gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
fastcgi_buffers 32 32k;
fastcgi_buffer_size 32k;
index index.php index.html index.htm;
include /etc/nginx/conf.d/*;
# server {
# listen 127.0.0.1:80;
# server_name 127.0.0.1;
# location /nginx_status {
# stub_status on;
# allow 127.0.0.1;
# deny all;
# }
# }
}
站点启用配置
server {
client_max_body_size 10M;
listen 80; ## listen for ipv4; this line is default and implied
#if ($http_x_forwarded_proto = "http") {
# return 301 https://moveyourmountain.org$request_uri;
#}
root /var/www/sites/moveyourmountain.org/;
# Make site accessible from http://localhost/
server_name moveyourmountain.org www.moveyourmountain.org lnp2.moveyourmountain.org;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params_ssl;
}
location /help {
try_files $uri $uri/ /help/index.php?q=$uri&$args;
}
location /blog {
try_files $uri $uri/ /blog/index.php?q=$uri&$args;
}
#location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
# expires 1y;
#}
}
很抱歉,我的配置有点奇怪和混乱,我已经为此工作了几天,尝试了我能找到的一切。另外,因为我读过一些案例,当他们的服务器重新启动时,它会快速运行一段时间,所以我尝试了一下。它没有改变任何东西,速度还是一样。我觉得你的/test.html是由php fpm处理的。在这种情况下,您应该调整它,而不是nginx本身。例如,增加fpm池中的子项数。此外,随着nginx worker阻止unix套接字操作,增加working_进程数也会很有用。目前,我是唯一一个访问此服务器的用户,所以我不确定增加working_进程将如何帮助1个请求。此外,PHP-FPM子项设置为264。我将尝试获取它,这样/test.html就不会经过PHP-FPM并返回报告。谢谢您不是单一用户—“ab”也提供服务-我应该澄清一下,我想,唯一的点击是我用AB发送的5个点击。我注释掉了所有与php try_文件和fastcgi位置块有关的行,没有任何更改:/