我在本地局域网中使用它,所以它应该相当快。
nginx 服务器使用 node.js 服务器来提供静态文件,因此必须通过 node.js 来下载文件,但是当我不使用 nginx 时这不是问题。
我已经尝试通过 nginx 直接提供文件来加快速度,但我认为这种方式设置不太好。我希望使用 node.js,即应用程序本身来处理要显示的内容...
在打开调试器的 Chrome 中,我可以看到状态为:206 - 部分内容,并且仅下载了 1.03MB 中的 31KB。1.1 分钟后,它变成红色,状态失败。等待时间:6ms 接收:1.1 分钟
google chrom 中的标题:
Request URL:http://192.168.1.16/production/assembly/script/production.js
Request Method:GET
Status Code:206 Partial Content
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Cookie:connect.sid=s%3Abls2qobcCaJ%2FyBNZwedtDR9N.0vD4Fi03H1bEdCszGsxIjjK0lZIjJhLnToWKFVxZOiE
Host:192.168.1.16
If-Range:"1081715-1350053827000"
Range:bytes=16090-16090
Referer:http://192.168.1.16/production/assembly/
User-Agent:Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
Response Headersview source
Accept-Ranges:bytes
Cache-Control:public, max-age=0
Connection:keep-alive
Content-Length:1
Content-Range:bytes 16090-16090/1081715
Content-Type:application/javascript
Date:Mon, 15 Oct 2012 09:18:50 GMT
ETag:"1081715-1350053827000"
Last-Modified:Fri, 12 Oct 2012 14:57:07 GMT
Server:nginx/1.1.19
X-Powered-By:Express
我的 nginx 配置:
文件 1:
user totty;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /home/totty/web/production01_server/node_modules/production/_logs/_NGINX_access.txt;
error_log /home/totty/web/production01_server/node_modules/production/_logs/_NGINX_error.txt;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
autoindex on;
include /home/totty/web/production01_server/_deployment/nginxConfigs/server/*;
}
前一个文件所包含的文件:
server {
# custom location for entry
# using only "/" instead of "/production/assembly" it
# would allow you to go to "thatip/". In this way
# we are limiting to "thatip/production/assembly/"
location /production/assembly/ {
# ip and port used in node.js
proxy_pass http://127.0.0.1:3000/;
}
location /production/assembly.mongo/ {
proxy_pass http://127.0.0.1:9000/;
proxy_redirect off;
}
location /production/assembly.logs/ {
autoindex on;
alias /home/totty/web/production01_server/node_modules/production/_logs/;
}
}
答案1
好的,问题是静态文件应该使用 nginx 服务器,因为 node.js 不适合服务器大型静态文件。