在存储服务上操作(storge)
1.安装依赖(st-01 st-02)
命令:[root@storage01 ~]# yum install -y pcre pcre-devel openssl openssl-devel gd-devel
命令:[root@storage02 ~]#yum install -y pcre pcre-devel openssl openssl-devel gd-devel
2.杀掉nginx进程后编译nginx(以st-01为例)
命令:[root@storage01 ~]# ps aux | grep nginx
命令:[root@storage01 ~]# kill -9 6462
3.重新编译nginx,添加模块
命令:[root@storage01 ~]# cd /myself_settings/nginx-1.7.8
命令:[root@storage01 nginx-1.7.8]# ./configure --prefix=/usr/local/nginx --with-http_image_filter_module --add-module=/myself_settings/fastdfs-nginx-module/src
命令:[root@storage01 nginx-1.7.8]# make && make install
4.配置nginx解析
命令:[root@storage01 nginx-1.7.8]# vim /usr/local/nginx/conf/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 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
##
location ~ group[1-3]/M00/(.+)_([0-9]+)x([0-9]+)\.(jpg|gif|png) { #这段往下为生成缩略图的配置
root /opt/fastdfs_storage_data/data;
ngx_fastdfs_module;
set $w $2;
set $h $3;
if ($w != "0") {
rewrite group1/M00(.+)_(\d+)x(\d+)\.(jpg|gif|png)$ group1/M00$1.$4 break;
}
if ($h != "0") {
rewrite group1/M00(.+)_(\d+)x(\d+)\.(jpg|gif|png)$ group1/M00$1.$4 break;
}
image_filter resize $w $h;
image_filter_buffer 2M;
try_files group[1-3]/M00$1.$4 $1.jpg;
}
##
location ~/group[1-3]/M00{
root /opt/fastdfs_storage_data/data;
ngx_fastdfs_module;
}
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;
# }
#}
命令:[root@storage02 nginx-1.7.8]# /usr/local/nginx/sbin/nginx #然后重启文件
注意:有多少存储服务器(storage)都要配置,否则会报404
5.测试
将一张图片放入/root下
命令:[root@storage01 ~]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/20200107204.png
打开浏览器输入http://192.168.175.10:8080/group1/M00/00/00/wKivCl4VntWAQjOrAAEpWNULvG4895_big.png
如下图:
上面的截图是原版,我们已经做完了缩略图,所以我们可以设置图片的规格大小
同样在浏览器上打开,前面路径不变,后面添加规格大小
注意:将后缀big删除换成规格大小,我调成200x200的, 中间的“x” 是小写字母x 不是乘号!
输入:http://192.168.175.10:8080/group1/M00/00/00/wKivCl4VntWAQjOrAAEpWNULvG4895_200x200.png
如下图:
这样FastDFS图片服务器的缩略图配置就做完了
来源:https://www.cnblogs.com/xiaolei123/p/12167971.html