(转)Nginx图片服务器
本文转至博客http://wenxin2009.iteye.com/blog/2117079
Nginx搭建图片服务器
Nginx下载地址:http://nginx.org/en/download.html
本例下载的是window版本nginx-1.6.1
以下是我本机操作说明:
下载完后,解压,并把它放到D:\tools\nginx-1.6.1,双击nginx.exe即可运行nginx。可通http://127.0.0.1访问到nginx欢迎界面,如下

也可在cmd中通过命令进行启停启动nginx:
start nginx //运行nginx
nginx -s stop // 停止nginx
nginx -s reload // 重新加载配置文件(如修改配置文件后,可通过该命令重新加载)
nginx -s quit // 退出nginx
nginx -v //可查nginx版本
在执行nginx命令时,出现了 windows nginx: [error] CreateFile() "logs/nginx.pid" failed 异常。原因是未指定
nginx.conf,指定该文件,启动命令如下:
D:\tools\nginx-1.6.1>nginx -c D:\tools\nginx-1.6.1\conf\nginx.conf

接下来我们配置图片服务器:
1、在本地建了一个D:\resourcesfile\images文件夹,里面放了一张png测试图片。
2、配置nginx.conf文件,配置文件内容如下:
- #user nobody;
- worker_processes 1;
- #error_log logs/error.log;
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
- #pid logs/nginx.pid;
- events {
- worker_connections 1024;
- }
- 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;
- server {
- listen 8089;#端口号
- server_name localhost;#本机
- charset utf-8;
- #access_log logs/host.access.log main;
- location ~ .*\.(gif|jpg|jpeg|png)$ {
- expires 24h;
- root D:/resourcesfile/images/;#指定图片存放路径
- access_log D:/tools/nginx-1.6.1/logs/log_test.log;#图片路径
- proxy_store on;
- proxy_store_access user:rw group:rw all:rw;
- proxy_temp_path D:/resourcesfile/images/;#图片路径
- proxy_redirect off;
- proxy_set_header Host 127.0.0.1;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- client_max_body_size 10m;
- client_body_buffer_size 1280k;
- proxy_connect_timeout 900;
- proxy_send_timeout 900;
- proxy_read_timeout 900;
- proxy_buffer_size 40k;
- proxy_buffers 40 320k;
- proxy_busy_buffers_size 640k;
- proxy_temp_file_write_size 640k;
- if ( !-e $request_filename)
- {
- proxy_pass http://127.0.0.1:8089;#代理访问地址
- }
- }
- location / {
- root html;
- index index.html index.htm;
- }
- 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;
- #}
- }
- # 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;
- # }
- #}
- }
配置完后,执行reload命令重新加载配置文件。然后进行访问图片,http://127.0.0.1:8089/036367.png
如果能访问,说明搭建成功。接下来还需对缓存和安全性进行研究。
===============================================================================
Linux下安装nginx,需要先安装Gcc编译器、PCRE库、zlib库、OpenSSL开发库。然后再安装nginx,
解压:tar -zxvf nginx-1.3.15.tar
编译安装命令:
./configure
make
make install
Linux下配置nginx图片服务器:
nginx version: nginx/0.6.35
nginx启动:/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
nginx关闭:ps -au|grep nginx
然后kill -9 进程id 或 killall -9 nginx
nginx.conf配置文件内容如下:
- user root;
- worker_processes 1;
- worker_rlimit_nofile 65535;
- #error_log logs/error.log;
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
- #pid logs/nginx.pid;
- events {
- worker_connections 12040;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- #Proxy_cache_path /pic/image_cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g ;
- #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;
- server {
- listen 80;
- server_name localhost;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- root html;
- index index.html index.htm;
- #proxy_pass http://192.168.10.223:1234;
- }
- #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;
- #}
- }
- # 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 7788;
- server_name localhost;
- # ssl on;
- # ssl_certificate /usr/local/nginx/conf/server.crt;
- # ssl_certificate_key /usr/local/nginx/conf/server_nopwd.key;
- charset utf-8;
- #charset koi8-r;
- location ~ (\.jsp)|(\.do) {
- proxy_pass http://127.0.0.1:7001;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_buffer_size 4k;
- proxy_buffers 4 32k;
- proxy_busy_buffers_size 64k;
- proxy_temp_file_write_size 64k;
- proxy_max_temp_file_size 512m;
- }
- }
- server {
- listen 8089;
- server_name localhost;
- charset utf-8;
- location ~ .*\.(gif|jpg|jpeg|png)$ {
- #allow 127.0.0.1;
- #deny all;
- #expires 24h;
- root /home/weblogic/pic/;
- access_log /opt/nginx/logs/log_test.log;
- proxy_store on;
- proxy_store_access user:rw group:rw all:rw;
- proxy_redirect off;
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $remote_addr;
- client_max_body_size 10m;
- client_body_buffer_size 1280k;
- proxy_connect_timeout 900;
- proxy_send_timeout 900;
- proxy_read_timeout 900;
- proxy_buffer_size 1024k;
- proxy_buffers 40 1024k;
- proxy_busy_buffers_size 1024k;
- proxy_temp_file_write_size 1024k;
- proxy_temp_path /home/weblogic/pic/;
- #Proxy_cache_path /pic/;
- if ( !-e $request_filename)
- {
- proxy_pass http://127.0.0.1:8089;
- }
- }
- location / {
- root html;
- index index.html index.htm;
- }
- #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;
- }
- }
- }
配置过程问题汇总:
1、failed Permission denied 权限问题
修改nginx.conf文件中
user nobody
改成:user root
2、nginx中Too many open files的问题
可参考相关博文 http://www.01happy.com/nginx-too-many-open-files/
http://zlr.iteye.com/blog/1961257
3、nginx recv() failed (104: Connection reset by peer) while reading response header from upstream
修改nginx.conf文件中:
if ( !-e $request_filename)
{
proxy_pass http://127.0.0.1:8089;
}
(转)Nginx图片服务器的更多相关文章
- 搭建Nginx图片服务器
搭建Nginx图片服务器 Part-I 安装Nginx 安装PCRE 下载 ngx_cache_purge 并解压,用来清除缓存 下载Nginx并解压 cd nginx-1.7.7 编译,--pref ...
- Nginx 图片服务器
文件服务器:后台如果是集群,每次请求都会到不同的服务器,所以每台服务器的图片文件等都要做同步处理,才能保证每次用户不管访问到哪台服务器都能获取一样的资源.这种做法开销会很大,专门使用 nginx 作为 ...
- 04_安装Nginx图片服务器
一.安装Nginx 先安装Nginx,看我之前发的文章: 搭建Nginx服务器 二.安装vsftpd 再安装vsftpd组件,看我之前发的文章: Linux安装ftp组件 三.开始搭建Nginx图片服 ...
- 第一次项目上Linux服务器(八:——搭建Nginx图片服务器)
一.准备工作 安装Nginx,参考历史博客 二.搭建Nginx图片服务器 1.效果 例如:图片通过xftp服务上传到/home/java/upload目录下,我想通过访问Nginx服务器来访问xftp ...
- 【图片服务器】搭建Nginx图片服务器
一.安装Nginx 二.安装vsftpd 三.开始搭建Nginx图片服务器 1.效果 例如:图片通过ftp服务上传到/home/ftpuser/www/images目录下,我想通过访问Nginx服务器 ...
- Windows下搭建Nginx图片服务器
在项目最开始,上传图片的时候,服务器先保存原图再使用ImageMagick生成上传图片缩略图,这种方法有很多缺点,例如生成的缩略图的大小是固定的,不能动态请求指定大小的缩略图. 虽然有非常多的图片云存 ...
- 【Nginx】配置nginx图片服务器
想通过nginx来访问服务器上的图片 可以搭建一个nginx图片服务器. 做法如下: 先安装nginx,这里直接用yum来进行安装的 安装方法如下: https://blog.csdn.net/iml ...
- centos7 nginx图片 服务器可以访问ftp用户上传的图片资源的配置
注:本文参考了csdn:JAVA_DIRECTION的<nginx和ftp搭建图片服务器>一文.在实践中其文在centos7中还是存在缺陷性的 一:前提条件:是成功的安装好了ftp服务器和 ...
- 基于Docker搭建Nginx图片服务器
前言 一般开发中,都会把图片上传到一个目录,然后将目录和文件名拼接存储在数据库中,但是,这种方法如果没弄好的话可能有一定的缺陷. 若项目搬迁,即时这台服务器本身还在用,存放在服务器的跟项目相关的图片也 ...
随机推荐
- day 11 大文件操作
1.f.read(), f.readline(), f.readlines() ##### 1. f.read() 整体读 返回字符串 In [2]: f = open("aaa.py ...
- RHCE模拟考试
真实考试环境说明: 你考试所用的真实物理机器会使用普通账号自动登陆,登陆后,桌面会有两个虚拟主机图标,分别是system1和system2.所有的考试操作都是在system1和system2上完成.S ...
- 4040 EZ系列之奖金 (拓扑)
4040 EZ系列之奖金 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题目描述 Description 由于无敌的WRN在2015年世界英俊帅 ...
- 我们一起学习WCF 第十篇Wcf中实现事务
数据一致性在工作中显得非常重要,有时候我们库中出现脏数据导致程序报错,但是又很难发现这样的错误,所以为了数据的完整性建议在程序中加入事物. 什么是事物:我们都有团队合作吧,比喻团队有3个人,a负责设计 ...
- javaweb(十一)——使用Cookie进行会话管理
一.会话的概念 会话可简单理解为:用户开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话. 有状态会话:一个同学来过教室,下次再来教室,我们会知道这个同学曾 ...
- Unity —— 通过鼠标点击控制物体移动
//ClickMove - - 通过鼠标点击控制物体移动 using System.Collections; using System.Collections.Generic; using Unity ...
- Office365创建通讯组
Office365创建通讯组 命令 new-DistributionGroup -Name 'test' -Members tom@msazure.cn 结果 命令 new-DistributionG ...
- 剑指offer-数值的整数方
数值的整数方 一.问题描述 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 二.算法思路 按照指数Exp的情况进行讨论. Exp> ...
- Python 招聘信息爬取及可视化
自学python的大四狗发现校招招python的屈指可数,全是C++.Java.PHP,但看了下社招岗位还是有的.于是为了更加确定有多少可能找到工作,就用python写了个爬虫爬取招聘信息,数据处理, ...
- webpack入门指南-step01
一.webpack是什么? web开发中常用到的静态资源主要有JavaScript.CSS.图片.Jade等文件,webpack中将静态资源文件称之为模块.webpack是一个模块打包工具(命令行工具 ...