我正在尝试静态文件服务。因此选择了最简单的设置。
/etc/hosts
我在(127.0.0.1 mysite.test
)中添加了
我在 nginx 中创建了一个 vhost,并在文件夹中放置了一个文件(test.mkv~3.5G)
我开始打它
- 铬合金- 开始时速度很慢,15 秒内速度飙升至 13MB/s,平均速度为 8MB/s
- 下载器- 开始时速度为 1.6MB/s,然后迅速攀升至 8MB/s,接下来的 2 分钟内,播放速度在 9-14MB/s 之间)
- 在docker中运行的自定义PHP脚本- 在 2 分钟内,速度从 1.2MB/s 缓慢增加到 8MB/s)
- 获得- 开始时速度非常慢,大约 15 秒后速度达到 14MB-16MB/s
鉴于它是本地主机,我预计最大速度很容易超过 1GB/s。
这是我的 nginx 配置(在带有英特尔芯片的 MacBook Pro 上运行)
Nginx 主要配置
worker_processes 4;
events {
worker_connections 1024;
multi_accept on;
}
http {
server_names_hash_max_size 1024;
server_names_hash_bucket_size 128;
fastcgi_buffers 32 4096k;
fastcgi_buffer_size 2048k;
proxy_buffering off;
include mime.types;
default_type application/octet-stream;
# Max File Upload Size (also needs to be set in php.ini)
client_max_body_size 120M;
gzip off;
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
sendfile on;
tcp_nodelay on;
tcp_nopush on;
keepalive_timeout 30;
reset_timedout_connection on;
Nginx 静态文件服务配置(里面也有一些 CORS 内容,但它们不应该影响单个文件的流式传输)
server {
listen 80;
listen 38888 default;
server_name mysite.test;
root /at/some/folder;
sendfile on;
aio off;
output_buffers 1 2m;
keepalive_timeout 15;
send_timeout 30s;
tcp_nopush on;
tcp_nodelay on;
client_max_body_size 102400m;
reset_timedout_connection on;
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT, HEAD' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8' always;
add_header 'Content-Length' 0 always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
return 204;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT, HEAD' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
}
try_files $uri $uri/ = 404;
}
}
有人可以建议如何改进本地主机上的静态文件服务吗?