`
m635674608
  • 浏览: 5001228 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

通过Nginx+mongodb-gridfs+squid实现简单的图片存储及图片缓存示例

 
阅读更多


图片存储

通过Nginx+mongodb-gridfs+squid实现简单的图片存储及图片缓存.

 

图片先从nginx本地cache里查找,然后到站点去找,再而到squid 里查找,都找不到最后才到mongodb-girdfs查找,然后把图片cachesquid.

 

Nginx编译安装

./configure--prefix=/usr/local/nginx --with-http_realip_module --with-http_addition_module--with-http_gzip_static_module --with-http_secure_link_module--with-http_stub_status_module --with-pcre=../pcre-8.02--add-module=../ngx_cache_purge-1.4 --with-zlib=../zlib-1.2.3/--add-module=../nginx-gridfs --add-module=./nginx_upstream_jvm_route/--with-http_stub_status_module

Make

Makeinstall

 

 

Nginx配置

user nobody;

worker_processes 4;

error_log logs/nginx_error.log  crit;

pid       /usr/local/nginx/nginx.pid;

worker_rlimit_nofile 20480;

events

{

 useepoll;

 worker_connections 20480;

}

http

{

 upstream cd {

   server  127.0.0.1:8082;

  }

 

 include      mime.types;

 default_type application/octet-stream;

 charset UTF-8;

 server_names_hash_bucket_size 128;

 client_header_buffer_size 32k; sendfile on;

 tcp_nopush    on;

 keepalive_timeout 60;

 tcp_nodelay on;

 proxy_connect_timeout 30;

 proxy_read_timeout 60;

 proxy_send_timeout 20;

 proxy_buffer_size 96k;

 proxy_buffers 8 256k;

 proxy_busy_buffers_size 512k;

 proxy_temp_file_write_size 512k;

 proxy_temp_path /usr/local/nginx/proxy_temp;

 proxy_cache_path /usr/local/nginx/wwwlevels=1:2 keys_zone=cache_one:200m inactive=1d max_size=200m;

gzip on;

 gzip_proxied any;

 gzip_min_length  1k;

 gzip_buffers     4 16k;

 gzip_http_version 1.0;

 gzip_comp_level 2;

 gzip_types       text/plain application/x-javascripttext/css application/xml;

 gzip_vary on;

server_tokens off;

 proxy_redirect off;

 proxy_set_header Host $host;

 proxy_set_header X-Real-IP $remote_addr;

 proxy_set_header X-Forwarded-For$http_x_forwarded_for;

{

  listen       80;

  server_name  192.168.2.248;

  index index.html;

  rewrite ^/image/(.*) /image/$1 last;

 

location ~ /purge(/.*)

   {

   proxy_cache_purge    cache_one$host$1$is_args$args;

   allow           all;

   deny          all;

   }   

 

 

location /  {

    proxy_pass http://cd;

}

 

location ~ .*\.(gif|png|jpg|jpge)$ {

    proxy_cache cache_one;

    proxy_cache_valid all 10m;

    proxy_cache_key $host$uri$is_args$args;

    proxy_pass http://cd;

    if (!-f $request_filename){

       proxy_pass http://192.168.2.248:8000;

       }

    }

 

access_log off;

 }

 

server

{

listen 8000;

server_name 192.168.2.241;

 

location /image/  {

 gridfs gfs

      field=filename

      type=string;

 mongo 192.168.2.241:38000;

}

 access_log off;

}

 

}

 

Mongodb配置

/usr/db/mongodb-linux-x86_64-2.0.2/bin/mongod--dbpath=/usr/db/data/sa --logpath=/usr/db/data/sa.log --port 38000 --fork--logappend --maxConns=500 --oplogSize=1000 –nohttpinterface

 


Squid配置

acl all src 0.0.0.0/0.0.0.0

acl manager proto cache_object

acl localhost src 127.0.0.1/255.255.255.255

acl to_localhost dst 127.0.0.0/8

acl SSL_ports port 443

acl Safe_ports port 80          # http

acl Safe_ports port 21          # ftp

acl Safe_ports port 443         # https

acl Safe_ports port 70          # gopher

acl Safe_ports port 210         # wais

acl Safe_ports port 1025-65535  # unregistered ports

acl Safe_ports port 280         # http-mgmt

acl Safe_ports port 488         # gss-http

acl Safe_ports port 591         # filemaker

acl Safe_ports port 777         # multiling http

acl CONNECT method CONNECT

acl Purge method PURGE

http_access allow all Purge

http_access allow manager localhost

http_access allow localhost

http_access allow all

icp_access allow all

http_port 8000 accel  vhost vport

cache_peer 192.168.2.241 parent 8000 0no-query originserver

hierarchy_stoplist cgi-bin ?

cache_mem 100 MB

maximum_object_size_in_memory 2000 KB

cache_dir ufs /home/cache 400 16 256  max-size=250000

cache_dir ufs /var/spool/squid 2000 16256       min-size=250000

maximum_object_size 409600 KB

cache_swap_low 80

cache_swap_high 85

logformat squid %ts.%03tu %6tr %>a%Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt

access_log /var/log/squid/access.log squid

cache_log /var/log/squid/cache.log

cache_store_log /var/log/squid/store.log

pid_filename /var/run/squid.pid

refresh_pattern -i \.gif$   100   20%     1440      ignore-reload

refresh_pattern -i \.jpg$    10    20%     20       ignore-reload

refresh_pattern -i \.png$   100   20%     1440      ignore-reload

refresh_pattern -i \.jpeg$  100   20%     1440      ignore-reload

refresh_pattern -i \.bmp$   100   20%     1440     ignore-reload

acl apache rep_header Server ^Apache

broken_vary_encoding allow apache

visible_hostname 192.168.2.248

dns_nameservers 202.96.134.33 8.8.8.8

hosts_file /etc/hosts

coredump_dir /var/spool/squid

 

squid2个地方存储,小于250k的图片存入内存,大于250K的图片存在磁盘

 

cache_dir ufs /home/cache 400 16 256  max-size=250000

cache_dir ufs /var/spool/squid 2000 16256   min-size=250000

通过把内存挂载到硬盘的方法,来把图片保存至内存,提高访问速度

 

效果

页面


访问效果


Squid缓存效果,这时停掉后端的mongodb,访问还是没有问题的.图片依然可以正常显示

 

 

http://www.51document.com/1365591863693.html

分享到:
评论

相关推荐

    ffmpeg+nginx+nginx-rtmp-module搭建个人直播平台

    ffmpeg+nginx+nginx-rtmp-module搭建个人直播平台。 使用说明(ffmpeg+nginx+rtmp-module已经整合,支持HTTP,具体配置查看conf/nginx.conf): 1.解压后,运行nginx_start.bat。(查看监控状态 ...

    nginx-gridfs-0.8.tar.gz

    Nginx的GridFS模块(nginx-gridfs)是Nginx的一个扩展,允许它直接与MongoDB的GridFS存储引擎交互,实现静态文件的上传和下载。GridFS是MongoDB提供的一种分布式文件系统,用于存储和检索大型文件,如图片、视频等,...

    Nginx与Nginx-GridFS的安装与配置

    Nginx-GridFS是Nginx的一个模块,用于提供对MongoDB的GridFS存储系统的直接访问,使得Web应用可以直接通过Nginx读取和存储MongoDB中的大文件,如图片、视频等。 首先,我们来了解一下Nginx的基本安装步骤: 1. **...

    nginx + nginx-http-flv-module-1.2.9

    通过在 Nginx 的 configure 脚本中添加模块路径,然后执行 `make` 和 `make install` 进行编译和安装。 4. **配置文件** 在 `conf` 目录下的 `nginx.conf` 文件是 Nginx 的主配置文件,其中需要添加或修改部分配置...

    Windows下一站式搭建ffmpeg推流+nginx-http-flv-module直播拉流+FLV.js播放环境.rar

    1、在Windows系统下,搭建ffmpeg推流+nginx-http-flv-module直播拉流+FLV.js播放环境,所需依赖相关资源文件。 2、适合初学、研究、验证视频直播部署方案的相关技术人员。

    nginx+php-fpm解决502 Bad Gateway.zip

    nginx+php-fpm解决502 Bad Gateway.zip

    Linux利用nginx-gridfs搭建部署nginx-gridfs-0.8.zip

    Linux利用nginx-gridfs搭建部署,nginx-gridfs-0.8 可用

    ffmpeg+nginx-rtmp-module+flv监控视频web展示

    FFmpeg、Nginx-RTMP-Module 和 FLV 监控视频Web展示是一个整合了实时流媒体处理、传输和播放的技术方案。这个方案适用于在Web端实现监控视频的实时展示,尤其对于需要构建远程监控系统或者直播平台的场景非常实用。...

    nginx-gridfs.tar.gz

    通过这个压缩包,用户可以设置Nginx来代理对MongoDB中存储的文件的请求,实现Web服务直接读写大文件的功能,而无需通过应用程序层处理文件流。这种方式优化了Web服务器性能,减少了应用程序的复杂性,并利用了...

    nginx-gridfs.tgz

    Nginx-GridFS允许通过Nginx直接代理到MongoDB的GridFS,从而实现快速、高效地分发大文件。 **Nginx介绍** Nginx是一款开源的高性能HTTP和反向代理服务器,以其事件驱动的异步非阻塞模型而闻名,这使得它在高并发...

    linux nginx-gridfs

    Linux Nginx-GridFS是将MongoDB的GridFS存储系统与Nginx Web服务器集成的一种解决方案,用于高效地提供静态文件服务,如视频、图片等大文件的存储和访问。这种组合允许你在高流量环境下实现高性能的内容分发,特别...

    Nginx-gridfs插件安装

    通过安装Nginx-gridfs插件并配置好MongoDB的索引,现在你可以通过URL直接访问存储在MongoDB中的文件。例如,如果你有一个名为`example.txt`的文件存储在`mydb.fs`中,用户可以通过以下URL访问它: ``` ...

    nginx1.16.1+nginx-upload-module-2.3.0.zip

    【标题】"nginx1.16.1+nginx-upload-module-2.3.0.zip" 涉及的核心知识点是 Nginx 和一个特定的模块 —— nginx-upload-module。Nginx 是一款高性能的 Web 服务器和反向代理服务器,广泛应用于高并发场景,其轻量级...

    nginx带nginx-http-flv模块windows编译版rtmp

    **Nginx与Nginx-RTMP及Nginx-HTTP-FLV模块** Nginx是一款高性能、轻量级的Web服务器/反向代理服务器,被广泛应用于高并发场景,尤其在处理静态文件、HTTP缓存以及反向代理等方面表现出色。Nginx以其高效的事件驱动...

    PHP高级工程师必知必会Nginx+keepalived+MongoDB+haproxy+Sphinx实现分布式集群部署实战视频

    本文将围绕“Nginx + keepalived + MongoDB + haproxy + Sphinx”这一技术栈,详细介绍如何实现一个稳定的分布式集群部署方案。 #### 二、关键技术解析 ##### 1. Nginx **定义**:Nginx是一款高性能的HTTP和反向...

    nginx1.16+nginx-upstream-check-module-master+nginx-upload-module

    此外,`nginx-upload-module`还能与后端应用程序集成,例如通过POST请求将上传信息传递给PHP、Java等后端服务,实现文件的存储和处理。 在实际部署中,这三个组件通常一起使用,构建一个具备健康检查和文件上传功能...

    nginx-gridfs

    **Nginx-GridFS** 是一个开源项目,它允许用户通过Nginx Web服务器直接访问存储在MongoDB中的文件,使用GridFS作为文件存储系统。这个解决方案将高性能的Nginx与MongoDB的分布式文件系统相结合,为大规模的静态内容...

    nginx+ffmpeg+nginx-http-flv-module+html资源包

    这个资源包提供了一种简单而有效的方法来建立一个基础的流媒体服务系统,特别适合于对实时视频传输有需求的小型或中型企业。同时,它也为开发者提供了进一步定制和优化流媒体服务的基础。在实际应用中,可能还需要...

    nginx+lua+docker+docker-compose实现简单服务分发

    nginx+lua+docker+docker-compose实现简单服务分发

    FastDFS+Nginx+libfastcommon+fastdfs-nginx-module

    然后,我们需要安装fastdfs-nginx-module,这是一个让Nginx支持FastDFS的模块,可以实现通过Nginx直接访问存储在FastDFS中的文件。 5. 安装fastdfs-nginx-module: - 获取fastdfs-nginx-module源代码并解压。 - ...

Global site tag (gtag.js) - Google Analytics