在nginx.conf文件中的FASTDFS配置如下:
文件1:nginx.conf
user root;
worker_processes 24;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
worker_rlimit_nofile 30000;
events {
use epoll;
worker_connections 30000;
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off; #关闭版本显示
log_format main '[$time_local] -- $remote_addr -- $remote_port "$request_method $request_uri $server_protocol" $status "$upstream_response_time" -- "$request_time" -- "$host $server_addr $server_port $server_name" - "$http_referer"';
access_log logs/access.log main;
upstream game_server {
server 192.168.11.11:8012;
server 192.168.11.12:8012;
}
upstream gamefw_server {
server 192.168.11.11:8112;
server 192.168.11.12:8112;
}
####################fast dfs upstream begin#############################
upstream group1_server {
server 192.168.11.206:9000 max_fails=1 fail_timeout=30s;
}
####################fast dfs upstream end #############################
sendfile on;
tcp_nopush on;
keepalive_timeout 300;
gzip on;
gzip_buffers 4 16k;
gzip_comp_level 6;
gzip_min_length 1000;
gzip_types application/x-javascript application/xml text/css text/plain;
gzip_vary on;
#client_body_temp on;
#client_body_buffer_size 128k;
client_header_buffer_size 8k;
large_client_header_buffers 4 16k;
client_header_timeout 120s;
client_body_timeout 120s;
client_max_body_size 100M;
client_body_buffer_size 512k;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_cache_key "$scheme$host$request_uri";
proxy_cache_path /home/nginx/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
include nginx_v.conf;
}
文件2:nginx_v.conf
server {
listen 9000;
server_name lili*.game.cn;
client_max_body_size 300m;
charset utf-8;
proxy_next_upstream http_502 http_504 http_500 http_404 error timeout invalid_header;
#如果需要开启HTTP强制跳转成https请开启下面的配置,前期可以先不放开,等运行稳定后再开启
#rewrite ^(.*)$ https://$host:443$1 permanent;
#access_log logs/host.access.log main;
# if ($request_uri ~ ^(/user/m/login|/user/m/loginkey|/user/m/login/checkkey|/m/login|/sys/m/login|/views/getpass1.html|/views/register.html|/user/m/user/findpasssave)(.*)) {
# return 301 https://$host:443$request_uri;
# }
# if ($request_uri ~ ^(/mhs/NetSyEdu/watchvideo)(.*)) {
# return 301 https://$host$request_uri;
# }
# if ($request_uri ~ ^(/mhs/NetMfEdu/watchvideo)(.*)) {
# return 301 https://$host$request_uri;
# }
# if ($request_uri ~ ^(/mhs/NetSyEdu/viewdocument)(.*)) {
# return 301 https://$host$request_uri;
# }
# if ($request_uri ~ ^(/mhs/NetMfEdu/viewdocument)(.*)) {
#return 301 https://$host$request_uri;
# }
# if ($request_uri ~ ^(/mhs/NetSyEdu/toTest)(.*)) {
# return 301 https://$host$request_uri;
# }
# if ($request_uri ~ ^(/mhs/NetMfEdu/toTest)(.*)) {
# return 301 https://$host$request_uri;
# }
location /nginxstatus {
# stub_status on;
access_log off;
#加入访问限制
#allow 定时任务sysip;
#allow 运维任务sysip;
#allow 自动发布系统ip;
#deny all;
#allow 192.168.200.202;
# allow 192.168.200.203;
# allow 192.168.200.201;
# deny all;
}
location / {
proxy_set_header Host $host:$server_port;
# proxy_redirect http:// https://;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://game_server/;
client_max_body_size 20m;
}
location /risdz {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://gamefw_server/;
client_max_body_size 20m;
}
##############fastdfs config begin##################################
location /group1/M00 {
root /data00/data;
ngx_fastdfs_module;
}
location /group1/M01 {
root /data01/data;
ngx_fastdfs_module;
}
location /group1/M02 {
root /data02/data;
ngx_fastdfs_module;
}
location /group1/M03 {
root /data03/data;
ngx_fastdfs_module;
}
##############fastdfs config begin##################################
}
#HTTPS server
server {
listen 443 ssl;
server_name localhost;
#ssl ;
ssl_certificate ../ssl/server.crt;
ssl_certificate_key ../ssl/server.key;
ssl_session_timeout 5m;
#ssl_protocols SSLv2 SSLv3 TLSv1;
#ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "LOW !3DES !MD5 !RC4 !***";
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_redirect http:// https://;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://game_server;
}
##############fastdfs config begin##################################
location /group1/M00 {
root /data00/data;
ngx_fastdfs_module;
}
location /group1/M01 {
root /data01/data;
ngx_fastdfs_module;
}
location /group1/M02 {
root /data02/data;
ngx_fastdfs_module;
}
location /group1/M03 {
root /data03/data;
ngx_fastdfs_module;
}
##############fastdfs config begin##################################
}
查看图片的方法:
有个图片ra0KzlviQSiADCkCAGHkfkT9QK8875.JPG,在/data00/data/23/4D 目录中,
根据nginx.conf文件中的配置可以看出FASTDFS 服务器和端口是192.168.11.206:9000
在nginx_v.conf文件中的配置可以看出FASTDFS 服务器有4个存储目录,
图片文件存在/data00-3/data 目录中。
在查询的时候,需要用别名目录查询,即:/group1/M0-3
查看链接如下:
域名查看:https://lili*.game.cn:443/group1/M00/23/4D/ra0KzlviQRiAOspeAAMiFz_m_wA663.jpg
服务器查看:192.168.11.206:9000/group1/M00/23/4D/ra0KzlviQRiAOspeAAMiFz_m_wA663.jpg