搭建Nginx图片服务器

Part-I 安装Nginx

  1. 安装PCRE
  2. 下载 ngx_cache_purge 并解压,用来清除缓存
  3. 下载Nginx并解压
  4. cd nginx-1.7.7
  5. 编译,--prefix使用默认值,则nginx安装在/usr/local/nginx
    ./configure    --user=www    --group=www    --add-module=../ngx_cache_purge-1.0
    --with-http_stub_status_module --with-http_ssl_module
    make && make install

Part-II 配置

vim /usr/local/nginx/conf/nginx.conf,并编辑如下:

user  www www;
worker_processes 8; error_log /data3/nginx/error.log crit;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; pid /usr/local/nginx/nginx.pid; events {
use epoll;
worker_connections 65535;
} http {
include mime.types;
default_type application/octet-stream;
charset utf-8; server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m; sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on; client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k; gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plainapplication/x-javascript text/css application/xml;
gzip_vary on; # proxy_temp_path 和 proxy_cache_path 必须在同一分区
proxy_temp_path /data0/proxy_temp_dir;
# 设置web缓存区名称为cahche_one,内存缓存空间大小为200M,1天没有被访问的内容自动清除硬盘缓存空间大小为300G
proxy_cache_path /data0/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g; # upstream backend_server{
# server 192.168.1.121:80 weight=1 max_fail=2 fail_timeout=30s;
# server 192.168.1.122:80 weight=1 max_fail=2 fail_timeout=30s;
# server 192.168.1.123:80 weight=1 max_fail=2 fail_timeout=30s;
# } #以下为缓存服务器 log_format cache '***$time_local \n'
' $upstream_cache_status \n'
' $remote_addr, $http_x_forwarded_for \n'
' Cache-Control: $upstream_http_cache_control \n'
' Expires: $upstream_http_expires \n'
' "$request"($status) \n'
' "$http_user_agent" \n'; server {
listen 80;
server_name 192.168.1.120; location / {
proxy_cache cache_one;
# 对不同的HTTP状态码设置不同的缓存时间
proxy_cache_valid 200 304 12h;
#以域名、URI、参数组合成web服务器的key值,Ngnix根据key值哈希,存储缓存内容到二级缓存目录内
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
#此处跳转到真实图片服务器
proxy_pass http://192.168.1.120:8080; access_log /data3/nginx/cache.log cache; expires 1d;
} location ~ /purge(/.*){
#设置只允许指定的ip或ip段才可以清除url缓存
#allow 127.0.0.1;
#allow 192.168.0.0/16;
#deny all;
proxy_cache_purge cache_one $host$1$is_args$args;
} # #扩展名为.php、.jsp、.cig结尾的动态应用程序不缓存
# location ~.*\.(php|jsp|cgi)?$
# {
# proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $remote_addr;
# proxy_pass http://backend_server;
# } access_log off; #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} #真实的图片服务器
server{
listen 8080;
server_name localhost;
location /{
root /data0/images/;
} #访问日志,一般都off掉
access_log /data3/nginx/access.log combined;
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

到此,Nginx图片服务区搭建完毕。 在/data0/images/下放入一张图片 200.jpg测试之 访问 http://192.168.1.120/200.jpg, cache_log记录如下:

***12/Nov/2014:16:15:26 +0800
MISS
192.168.1.19, -
Cache-Control: -
Expires: -
"GET /200.jpg HTTP/1.1"(200)
"Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0" ***12/Nov/2014:16:15:38 +0800
HIT
192.168.1.19, -
Cache-Control: -
Expires: -
"GET /200.jpg HTTP/1.1"(200)
"Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0"

访问 http://192.168.1.120/purge/200.jpg 清除缓存

搭建Nginx图片服务器的更多相关文章

  1. 第一次项目上Linux服务器(八:——搭建Nginx图片服务器)

    一.准备工作 安装Nginx,参考历史博客 二.搭建Nginx图片服务器 1.效果 例如:图片通过xftp服务上传到/home/java/upload目录下,我想通过访问Nginx服务器来访问xftp ...

  2. 【图片服务器】搭建Nginx图片服务器

    一.安装Nginx 二.安装vsftpd 三.开始搭建Nginx图片服务器 1.效果 例如:图片通过ftp服务上传到/home/ftpuser/www/images目录下,我想通过访问Nginx服务器 ...

  3. Windows下搭建Nginx图片服务器

    在项目最开始,上传图片的时候,服务器先保存原图再使用ImageMagick生成上传图片缩略图,这种方法有很多缺点,例如生成的缩略图的大小是固定的,不能动态请求指定大小的缩略图. 虽然有非常多的图片云存 ...

  4. 基于Docker搭建Nginx图片服务器

    前言 一般开发中,都会把图片上传到一个目录,然后将目录和文件名拼接存储在数据库中,但是,这种方法如果没弄好的话可能有一定的缺陷. 若项目搬迁,即时这台服务器本身还在用,存放在服务器的跟项目相关的图片也 ...

  5. 搭建Nginx图片服务器(Linux)

    知识点: 在Linux系统上安装Nginx服务器,配置图片访问路径 通过ftp上传图片到,指定路径,通过浏览器访问指定路径中的图片 参考博客:http://blog.csdn.net/maoyuanm ...

  6. linux搭建nginx图片服务器

    1:参考http://blog.csdn.net/u012401711/article/details/53525908

  7. 04_安装Nginx图片服务器

    一.安装Nginx 先安装Nginx,看我之前发的文章: 搭建Nginx服务器 二.安装vsftpd 再安装vsftpd组件,看我之前发的文章: Linux安装ftp组件 三.开始搭建Nginx图片服 ...

  8. (转)Nginx图片服务器

    本文转至博客http://wenxin2009.iteye.com/blog/2117079 Nginx搭建图片服务器 Nginx下载地址:http://nginx.org/en/download.h ...

  9. FastDFS搭建单机图片服务器(二)

    防丢失转载:https://blog.csdn.net/MissEel/article/details/80856194 根据 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署 和 ...

随机推荐

  1. 【转】使用NetBeans和Eclipse开发PHP应用程序

    [51CTO独家特稿]各位用户如果单独看NetBeans和Eclipse的市场占有率,你可能会认为使用其中任何一种IDE开发PHP应用程序都没有 问题,例如: 1.NetBeans:一款开源的集成开发 ...

  2. memcache 分布式,算法实现

    memcached 虽然称为 “ 分布式 ” 缓存服务器,但服务器端并没有 “ 分布式 ” 功能.每个服务器都是完全独立和隔离的服务. memcached 的分布式,则是完全由客户端程序库实现的. 这 ...

  3. 【跟我一起学Python吧】Python解释执行原理

    这里的解释执行是相对于编译执行而言的.我们都知道,使用C/C++之类的编译性语言编写的程序,是需要从源文件转换成计算机使用的机器语言,经过链接器链接之后形成了二进制的可执行文件.运行该程序的时候,就可 ...

  4. MDI端口和MDIX端口是什么? 又有什么作用?

    是网线的标准A类接法和B类接法.也就是人们通常所说的交叉网线和直联网线.直联网线就是 白黄 黄 白绿 蓝 白兰 绿 白棕 棕 另一端同样如此.交叉网线就是 另一端的1和3,2和6对调.这样就成了交叉网 ...

  5. [LeetCode] Single Number III ( a New Questions Added today)

    Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...

  6. 关于LyX的一些小问题

    LyX转HTML(MS WORD)的脚本elyxer的更新: 首先从官网下载最新版的软件包.解压后,在命令行下python install.py执行安装(直接双击install.py应该也可以),py ...

  7. Tkinter教程之Entry篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811302 #Tkinter教程之Entry篇#Entry用来输入单行文本'''1.第一个En ...

  8. leetcode@ [354] Russian Doll Envelopes (Dynamic Programming)

    https://leetcode.com/problems/russian-doll-envelopes/ You have a number of envelopes with widths and ...

  9. Emacs和它的朋友们——阅读源代码篇(转)

    正如那本<Code Reading>一书中指出的那样,源代码阅读一直没有被很好的重 视:你上大学的时候有“代码阅读”这门课吗?相信没有. 1 Source Insight 谈到阅读源代码, ...

  10. Hibernate之HQL查询

    一.Hibernate 提供了以下几种检索对象的方式: 导航对象图检索方式: 根据已经加载的对象导航到其他对象 OID 检索方式: 按照对象的 OID 来检索对象 HQL 检索方式:使用面向对象的 H ...