How to Build a FastDFS Distributed File System with Nginx and cpolar for Remote Access
This step‑by‑step guide shows how to install FastDFS on a Linux server, configure its tracker and storage nodes, integrate it with Nginx, and expose the file service to the Internet using the cpolar tunneling tool, all with detailed commands and configuration files.
FastDFS is an open‑source lightweight distributed file system that manages file storage, synchronization, and access, making it ideal for online services such as photo albums and video sites. By installing FastDFS locally and forwarding the uploaded files through cpolar, you can dramatically reduce server costs while providing high‑availability file services.
1. Install FastDFS locally
1.1 Environment installation
yum -y install gcc-c++ yum -y install libevent1.2 Install libfastcommon
Download libfastcommon from GitHub and extract it.
cd /usr/local
wget https://github.com/happyfish100/libfastcommon/releases/download/V1.0.7/libfastcommonV1.0.7.tar.gz
tar -zxvf libfastcommonV1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh
./make.sh install
cp /usr/lib64/libfastcommon.so /usr/lib/1.3 Install FastDFS
Download FastDFS source, extract, compile and install.
cd /usr/local
wget https://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz/download -O fastdfs-nginx-module_v1.16.tar.gz
wget https://sourceforge.net/projects/fastdfs/ -O FastDFS_v5.05.tar.gz
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh install
cp conf/* /etc/fdfs/1.4 Configure Tracker
Edit /etc/fdfs/tracker.conf and set base_path=/home/fastdfs. Then create the directory and start the tracker.
mkdir /home/fastdfs
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restartAdd the start command to /etc/rc.d/rc.local for automatic boot.
1.5 Configure Storage
Edit /etc/fdfs/storage.conf to set base_path=/home/fastdfs, store_path0=/home/fastdfs/fdfs_storage, and the tracker server IP (e.g., tracker_server=192.168.1.100:22122). Create the storage directory and start the storage daemon.
mkdir /home/fastdfs/fdfs_storage
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restartAdd the storage start command to /etc/rc.d/rc.local for boot‑time launch.
1.6 Test upload and download
Modify /etc/fdfs/client.conf with the same base_path and tracker address, then use /usr/bin/fdfs_test to upload a file.
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/local/test23.pngThe command returns a file URL, which can be accessed via Nginx after integration.
1.7 Integrate with Nginx
Download the FastDFS Nginx module, extract it, and compile Nginx with the module.
cd /usr/local
wget http://nginx.org/en/download.html -O nginx-1.16.1.tar.gz
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure \
--prefix=/usr/local/nginx \
--add-module=/usr/local/fastdfs-nginx-module/src \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
make
make installCopy the generated mod_fastdfs.conf to /etc/fdfs/ and adjust paths (e.g., base_path=/home/fastdfs, store_path0=/home/fastdfs/fdfs_storage, url_have_group_name=true).
1.8 Configure Nginx
Add a server block to /usr/local/nginx/conf/nginx.conf to listen on a custom port (e.g., 8089) and route FastDFS URLs.
server {
listen 8089;
server_name 192.168.59.133;
location /group1/M00/ {
ngx_fastdfs_module;
}
}Start Nginx and ensure the PID directory exists.
mkdir -p /var/run/nginx
/usr/local/nginx/sbin/nginx2. Test LAN access
Upload a file again with fdfs_test and open the returned URL through the Nginx server to verify the file is served correctly.
3. Install cpolar for internet tunneling
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
cpolar authtoken YOUR_TOKEN
sudo systemctl enable cpolar
sudo systemctl start cpolar4. Configure public address
Create an HTTP tunnel in the cpolar web UI that forwards to the Nginx port (8089). Use the generated public URL to access FastDFS files from anywhere.
5. Reserve a fixed sub‑domain
Upgrade to a paid cpolar plan, reserve a sub‑domain (e.g., fasttest), and bind it to the tunnel. The fixed address remains stable as long as the tunnel stays online.
6. Verify remote access
Open the reserved sub‑domain in a browser, append the FastDFS file path, and confirm the image loads, proving that the distributed file system is reachable over the public internet without a dedicated IP.
All steps together provide a complete, low‑cost solution for deploying a FastDFS cluster, exposing it via Nginx, and making it reachable from anywhere through a stable cpolar public sub‑domain.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
