nginx+mongodb-gridfs+squid

原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://1008305.blog.51cto.com/998305/885340

 

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

Make install

 

 

Nginx配置

user nobody;

worker_processes 4;

error_log  logs/nginx_error.log  crit;

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

worker_rlimit_nofile 20480;

events

{

 use epoll;

 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/www levels=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-javascript text/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;

 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 0 no-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 16 256       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 16 256   min-size=250000

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

 

效果

页面

 

 

访问效果

 

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

 

 

本文出自 “呼呼” 博客,请务必保留此出处http://1008305.blog.51cto.com/998305/885340

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Nginx是一个高性能的开源Web服务器,同时也可以用作反向代理服务器、负载均衡器和流媒体服务器。Nginx的Rtmp-Module是一个第三方模块,它为Nginx服务器添加了RTMP(Real-Time Messaging Protocol)支持,使其可以充当一个流媒体服务器。FFmpeg是一个跨平台的音视频处理工具,它可以用来进行多媒体文件的转码、编解码、录制和流媒体传输等操作。 引用中提到了使用Nginx Nginx-Rtmp-Module Ffmpeg搭建流媒体服务器的方法。具体配置可以查看conf/nginx.conf文件。首先需要解压文件,然后运行nginx_start.bat文件来启动Nginx服务器。这样就可以使用Nginx服务器提供的RTMP服务,通过FFmpeg推送一个RTMP流到Nginx,然后客户端可以通过访问Nginx来收看实时视频流。还可以使用HLS(HTTP Live Streaming)协议,通过HTTP协议来访问Nginx服务器并收看视频流,但是FFmpeg推送流仍然是RTMP的。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器服务器](https://blog.csdn.net/sinat_16643223/article/details/115108327)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [ffmpeg+nginx+nginx-rtmp-module搭建个人直播平台](https://download.csdn.net/download/qq_29114677/13012815)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值