我正在努力尝试使用NGINX在我的页面上加载静态内容,以下是我当前的配置。我的目标是让我的页面加载更快,这就是为什么我想通过NGINX加载静态内容,但我注意到我的页面的加载时间是相同的。
文件路径:etc/nginx/default
server {
listen 80 default_server;
server_name default;
root /home/forge/site/public;
location / {
proxy_pass http://43.35.49.160/;
try_files $uri $uri/ /index.php?$query_string;
}
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
access_log logs/static.log; # I don't usually include a static log
}
# Feed
location ~* \.(?:rss|atom)$ {
expires 1h;
add_header Cache-Control "public";
}
#include folder/file-name.conf;
}
curl -X GET -I http://45.33.69.160/
HTTP/1.1 200 OK
Server: nginx/1.6.3
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: no-cache
Date: Sat, 09 May 2015 15:09:02 GMT
Set-Cookie: XSRF-TOKEN=eyJpdiI6IkVNZ205RjhuNWI2aUtEOUxRbjJSdUE9PSIsInZhbHVlIjoiN2RtSlJVZUZ6ZFpWNUNETElZOTNuK1ZzQW5Lcmw5UTVKVmo1REFRT2w0cVJoS3IxUitaOWNKYkh5NERrQXZ5VXpjbmNkSlZ0NTFwXC9XNGVxQ0xVYXlBPT0iLCJtYWMiOiI4Yjk4NjI1YjdjMDgxMzJiOTk4MzIxNmUzOTMxM2JiNDY2OTc4ZTZkNzI4Y2IxNjZlYmViNTAyYmZhY2ZlYjYzIn0%3D; expires=Sat, 09-May-2015 17:09:02 GMT; Max-Age=7200; path=/
Set-Cookie: laravel_session=eyJpdiI6Ik5zKzRcLzBEWE5mUjVhUlwvVE9GeWk3Zz09IiwidmFsdWUiOiJCT0pqaWFFQlhCdlJNTGlMZEV3dlg0K2RjTEVrY1dpNU5TbzB6NFBnMzU5Q2J6dzV5S25GR2pERVpKY2taYndOMG1ZRFcxUUZqQmFrUEREKzdCaFltZz09IiwibWFjIjoiMmJhYjBmNmMzMWQwNTIwMTFjMGFiZGJkY2MyNWRiYzAzMzU3OGU4MDliZGFlZWQzNzQ3MTNmOTcyYzY0NjMyNiJ9; expires=Sat, 09-May-2015 17:09:02 GMT; Max-Age=7200; path=/; httponly
我尝试加载其中一个文件css/bootstrap.min.css
ab -c 20 -n 1000 http://45.33.69.160/css/bootstrap.min.css
结果:
This is ApacheBench, Version 2.3 <$Revision: 1638069 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 45.33.69.160 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/1.6.3
Server Hostname: 45.33.69.160
Server Port: 80
Document Path: /css/bootstrap.min.css
Document Length: 78358 bytes
Concurrency Level: 20
Time taken for tests: 0.239 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 78593000 bytes
HTML transferred: 78358000 bytes
Requests per second: 4184.42 [#/sec] (mean)
Time per request: 4.780 [ms] (mean)
Time per request: 0.239 [ms] (mean, across all concurrent requests)
Transfer rate: 321157.98 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 0.7 2 3
Processing: 1 3 0.8 3 5
Waiting: 0 1 0.8 1 4
Total: 3 5 0.7 5 7
Percentage of the requests served within a certain time (ms)
50% 5
66% 5
75% 5
80% 5
90% 6
95% 6
98% 6
99% 7
100% 7 (longest request)
注意: Time taken for tests: 0.239 seconds
在有/无静态内容配置的情况下,内容的加载时间似乎相同。它不是更快吗?
出于某种原因,配置似乎根本没有设置。 有人可以指出我在这里做错了什么吗? 建议或反馈将不胜感激!