FastDFS配置Nginx模块

简介:

#

#fastdfs-nginx-module:下载地址

#Nginx1.10.1 下载地址

#ngx-cache-purge:下载地址

#nginx 缓存:详细介绍

#nginx 官方模块详解:http://nginx.org/en/docs/


#nginx 安装(Tracker节点)

#Nginx缓存和反向代理

#下载软件

1
2
[root@Tracker ~] # wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
[root@Tracker ~] # wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz

#解压ngx_cache_purge

1
[root@Tracker ~] # tar -xf ngx_cache_purge-2.3.tar.gz

#编译安装nginx

#安装依赖包(EPEL源)

1
2
3
4
[root@Tracker ~] # cd nginx-1.10.1/
[root@Tracker nginx-1.10.1] # yum install -y pcre pcre-devel openssl-devel openssl gcc-c++ 
[root@Tracker nginx-1.10.1] # ./configure --prefix=/usr/local/nginx --add-module=/root/ngx_cache_purge-2.3 --with-http_stub_status_module --with-http_ssl_module 
[root@Tracker nginx-1.10.1] # make && make install


#修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
[root@Tracker ~] # cat /usr/local/nginx/conf/nginx.conf | grep -v "#" | grep -v "^$"
user root;
worker_processes  1;
events {
     worker_connections  1024;
}
http {
     include       mime.types;
     default_type  application /octet-stream ;
     sendfile        on;
     tcp_nopush     on;
     keepalive_timeout  65;
     
     proxy_cache_path  /usr/local/nginx/proxy_cache_path  levels=1:2 keys_zone=cache_one:500m inactive=1d max_size=10g;
     proxy_temp_path  /usr/local/nginx/proxy_tmp_path ;
     gzip  on;
     gzip_min_length 1k;
     gzip_buffers 4 16k;
     gzip_types       text /plain  application /x-javascript  text /css  application /xml  text /javascript  application /x-httpd-php ;
     gzip_vary on;
     upstream fdfs {
server 192.168.174.137:80 max_fails=3 fail_timeout=30s weight=1;
server 192.168.174.138:80 max_fails=3 fail_timeout=30s weight=1;
}
     server {
         listen       80;
         server_name  localhost;
         location / {
             root   html;
             index  index.html index.htm;
         }
location  /group1/M00  {
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_pass http: //fdfs ;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 600;
proxy_max_temp_file_size 10m;
proxy_busy_buffers_size 256k;
proxy_buffer_size 256k; 
proxy_buffers 4 256k; 
proxy_cache_valid 200 304 12h ;
       proxy_cache_valid 301 302 1m ;
      proxy_cache_valid any 1m;
proxy_cache cache_one;
proxy_cache_key $host$uri$is_args$args;
location ~  /purge (/.*) {
         allow 127.0.0.1 ;
         allow 192.168.174.0 /24  ;
         deny all ;
         proxy_cache_purge cache_one $host$1$is_args$args ;
         }
         error_page   500 502 503 504   /50x .html;
         location =  /50x .html {
             root   html;
         }
     }
}


#测试配置文件是否正确

1
2
3
[root@Tracker ~] # /usr/local/nginx/sbin/nginx -t
nginx: the configuration  file  /usr/local/nginx/conf/nginx .conf syntax is ok
nginx: configuration  file  /usr/local/nginx/conf/nginx .conf  test  is successful


#创建缓存目录

1
2
[root@Tracker ~] # mkdir -p /usr/local/nginx/proxy_temp_path
[root@Tracker ~] # mkdir -p /usr/local/nginx/proxy_cache_path

#启动服务

1
2
3
[root@Tracker ~] # /usr/local/nginx/sbin/nginx 
[root@Tracker ~] # netstat -lntup | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      8787 /nginx : master





#nginx 安装(两台Storage节点)

#下载软件

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@Storage_1 ~] # wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
[root@Storage_1 ~] # wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip
[root@Storage_1 ~] # tar -xf nginx-1.10.1.tar.gz 
[root@Storage_1 ~] # unzip master.zip 
[root@Storage_1 nginx-1.10.1] # yum install -y pcre pcre-devel openssl-devel openssl gcc-c++ 
[root@Storage_1 nginx-1.10.1] # ./configure --prefix=/usr/local/nginx --add-module=/root/fastdfs-nginx-module-master/src --with-http_stub_status_module --with-http_ssl_module
[root@Storage_1 nginx-1.10.1] # make && make install
[root@Storage_1 ~] # cp /root/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
[root@Storage_1 ~] # cp /root/fastdfs-master/conf/http.conf /etc/fdfs/
[root@Storage_1 ~] # cp /root/fastdfs-master/conf/mime.types  /etc/fdfs/
[root@Storage_1 ~] # mkdir /data/fdfs/Storage/data/group1
[root@Storage_1 ~] # ln -s /data/fdfs/Storage/data/ /data/fdfs/Storage/data/group1/M00 
[root@Storage_1 ~] # vim /etc/fdfs/mod_fastdfs.conf

#修改如下值

1
2
3
4
tracker_server=192.168.174.136:22122  #第40行
url_have_group_name =  true     #第53行
store_path0= /data/fdfs/Storage/    #第60行
log_filename= /usr/local/nginx/logs/mod_fastdfs .log    #第78行


#在server 字段内部增加如下location

1
[root@Storage_1 ~] # vim /usr/local/nginx/conf/nginx.conf
1
2
3
4
         location  /group1/M00  {
         root  /data/fdfs/Storage/data ;
          ngx_fastdfs_module;
         }


#测试配置文件

1
2
3
4
[root@Storage_1 ~] # /usr/local/nginx/sbin/nginx -t
ngx_http_fastdfs_set pid=5336
nginx: the configuration  file  /usr/local/nginx/conf/nginx .conf syntax is ok
nginx: configuration  file  /usr/local/nginx/conf/nginx .conf  test  is successful


#启动服务

#storage_1

1
2
3
4
5
[root@Storage_1 ~] # /usr/local/nginx/sbin/nginx 
ngx_http_fastdfs_set pid=5337
#storage_2
[root@Storage_2 ~] # /usr/local/nginx/sbin/nginx 
ngx_http_fastdfs_set pid=6263



1
2
3
4
5
6
7
8
9
10
[root@Storage_1 logs] # curl -I 192.168.174.138
HTTP /1 .1 200 OK
Server: nginx /1 .10.1
Date: Wed, 19 Apr 2017 22:34:44 GMT
Content-Type: text /html
Content-Length: 612
Last-Modified: Wed, 19 Apr 2017 22:06:36 GMT
Connection: keep-alive
ETag:  "58f7df6c-264"
Accept-Ranges: bytes


#若服务不能正常运行,将/usr/local/nginx/conf/nginx.conf 中第一行 user nobody 修改为 user root


1
2
3
4
5
6
7
8
9
10
[root@Storage_1 logs] # curl -I 192.168.174.137
HTTP /1 .1 200 OK
Server: nginx /1 .10.1
Date: Wed, 19 Apr 2017 13:35:50 GMT
Content-Type: text /html
Content-Length: 612
Last-Modified: Wed, 19 Apr 2017 13:03:25 GMT
Connection: keep-alive
ETag:  "58f7601d-264"
Accept-Ranges: bytes



#上传文件

1
2
3
[root@Tracker ~] # echo "hello" > test.txt
[root@Tracker ~] # fdfs_upload_file  /etc/fdfs/client.conf  test.txt
group1 /M00/00/00/wKiuiVj3aM-AbzDqAAAABncc3SA048 .txt


#Storage_1节点

wKioL1j3aU2hXJWtAAArfwsWmSw594.png


#Storage_2节点

wKiom1j3aU2D6OxzAAAhprPv8cY589.png

#stracker节点

wKiom1j3a3fifXn5AAAkOYM2WGM661.png



#进入缓存目录

1
2
3
4
[root@Tracker 3b] # pwd
/usr/local/nginx/proxy_cache_path/a/3b   (目录可能不一样)
[root@Tracker 3b] # ls
adc71d260066e8ae813898b1901e33ba









本文转自 chaunceyjiang  51CTO博客,原文链接:http://blog.51cto.com/cqwujiang/1917540,如需转载请自行联系原作者
目录
相关文章
|
15天前
|
移动开发 前端开发 JavaScript
前端vue2、vue3去掉url路由“ # ”号——nginx配置(一)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
49 0
|
15天前
|
JavaScript 前端开发 应用服务中间件
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
24 0
|
15天前
|
前端开发 JavaScript 应用服务中间件
前端vue2、vue3去掉url路由“ # ”号——nginx配置(二)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
47 0
|
1天前
|
安全 网络协议 应用服务中间件
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
|
5天前
|
Ubuntu 应用服务中间件 nginx
ubuntu编译安装nginx及安装nginx_upstream_check_module模块
以上是编译安装Nginx和安装 `nginx_upstream_check_module`模块的基本步骤。根据你的需求和环境,你可能需要进一步配置Nginx以满足特定的要求。
18 3
|
9天前
|
应用服务中间件 PHP nginx
php如何实现检测nginx配置的正确性
请确保在执行此操作时,PHP有足够的权限来执行Nginx命令和访问Nginx配置文件。另外,将上述代码嵌入到您的应用程序中时,要注意安全性,以防止潜在的命令注入攻击。
49 3
|
15天前
|
安全 应用服务中间件 网络安全
linux_nginx中添加ssl配置(open ssl)
linux_nginx中添加ssl配置(open ssl)
24 1
|
15天前
|
JSON JavaScript 前端开发
vue2_vite.config.js的proxy跨域配置和nginx配置代理有啥区别?
vue2_vite.config.js的proxy跨域配置和nginx配置代理有啥区别?
32 1
|
19天前
|
安全 应用服务中间件 网络安全
SSL原理、生成SSL密钥对、Nginx配置SSL
现在,你的Nginx虚拟主机应该已经配置了SSL,可以通过HTTPS安全访问。确保在生产环境中使用有效的SSL证书来保护通信的安全性。
30 0
|
21天前
|
域名解析 缓存 负载均衡
Nginx正向代理域名的配置
Nginx正向代理域名的配置