例如
服務根目錄是 http://192.168.0.100:8080/Server,想要加速靜態資源的訪問速度,所以把不同類型的靜態資源放在不同的服務下,以下是http模塊的配置
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_min_length 200; #最小壓縮文件大小
gzip_comp_level 9; #壓縮比率1--9
gzip_buffers 8 5120k; #壓縮緩衝區
gzip_types text/plain text/css image/png application/json text/xml application/javascript image/gif;
gzip_vary on; #前端服務緩存壓縮
output_buffers 8 5120k; #輸出緩衝區
postpone_output 5460; #輸出緩衝區
upstream server_static_image {
server 127.0.0.1:20000 weight=1;
server 127.0.0.1:20001 weight=1;
server 127.0.0.1:20002 weight=1;
server 127.0.0.1:20003 weight=1;
}
upstream server_static_css_js {
server 127.0.0.1:20004 weight=1;
server 127.0.0.1:20005 weight=1;
server 127.0.0.1:20006 weight=1;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#根目錄訪問主服務,包含api接口等服務
location /Server {
proxy_pass http://192.168.0.100:8080/Server;
}
#圖片分配四臺服務器
location /Server/statics/image {
proxy_pass http://server_static_image /statics/image;
}
#js和css分配三臺服務器
location /Server/statics/js{
proxy_pass http://server_static_css_js/statics/js;
}
location /Server/statics/js{
proxy_pass http://server_static_css_js/statics/css;
}
}
}