Backend Development 16 min read

Step‑by‑Step Guide to Deploy FastDFS with Nginx and cpolar for Remote File Access

This tutorial walks through installing FastDFS on a Linux server, configuring its tracker and storage nodes, integrating it with Nginx via the FastDFS‑nginx module, and exposing the service publicly using the cpolar tunneling tool, providing complete commands and configuration snippets for each step.

Top Architect
Top Architect
Top Architect
Step‑by‑Step Guide to Deploy FastDFS with Nginx and cpolar for Remote File Access

FastDFS is an open‑source lightweight distributed file system that manages file storage, synchronization, and access, making it ideal for image or video hosting services. By combining FastDFS with Nginx and the cpolar tunneling tool, you can build a low‑cost, high‑performance file service accessible over the internet.

1. Local FastDFS Setup

1.1 Environment Installation

Install the required compiler and libraries:

yum -y install gcc-c++
yum -y install libevent

1.2 Install libfastcommon

Download, extract and compile the official common library:

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

Copy the generated library to /usr/lib :

cp /usr/lib64/libfastcommon.so /usr/lib/

1.3 Install FastDFS

Download and compile FastDFS:

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_v5.05.tar.gz
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh install

Copy configuration files to /etc/fdfs and edit them:

cp conf/* /etc/fdfs/
vim /etc/fdfs/tracker.conf   # set base_path=/home/fastdfs
vim /etc/fdfs/storage.conf   # set base_path and store_path0 accordingly
vim /etc/fdfs/client.conf    # set base_path and tracker_server

1.4 Configure Tracker

Start the tracker and enable autostart:

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
vim /etc/rc.d/rc.local   # add the same command for boot

1.5 Configure Storage

Start the storage daemon and enable autostart:

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
vim /etc/rc.d/rc.local   # add the same command for boot

1.6 Test Upload/Download

Use the test client to upload a file and obtain its URL:

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/local/test23.png

1.7 Nginx Integration

Download the FastDFS‑nginx module, compile Nginx with it, and configure a server block to serve FastDFS files:

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
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
cd fastdfs-nginx-module/src
vim config   # replace /usr/local/ paths with /usr/
cp mod_fastdfs.conf /etc/fdfs/
cp /usr/lib64/libfdfsclient.so /usr/lib/

# Install Nginx dependencies
yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
# Download and compile Nginx with the module
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxvf nginx-1.16.1.tar.gz && cd nginx-1.16.1
./configure \
  --prefix=/usr/local/nginx \
  --pid-path=/var/run/nginx/nginx.pid \
  --lock-path=/var/lock/nginx.lock \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/temp/nginx/client \
  --add-module=/usr/local/fastdfs-nginx-module/src
make && make install

Add a server block to /usr/local/nginx/conf/nginx.conf :

server {
    listen 8089;
    server_name 192.168.59.133;
    location /group1/M00/ {
        ngx_fastdfs_module;
    }
}

1.8 Start Nginx

Run Nginx and ensure the PID directory exists:

/usr/local/nginx/sbin/nginx
mkdir -p /var/run/nginx

2. Install cpolar (Internet‑to‑LAN tunneling)

Install cpolar with the one‑line script, authenticate with your token, enable the service and start it:

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 cpolar

3. Configure Public Access

Create an HTTP tunnel pointing to the Nginx port (8089) and obtain a public URL. For a stable address, reserve a sub‑domain in cpolar’s dashboard and bind it to the tunnel.

4. Verify Remote Access

Open the public URL in a browser; the previously uploaded image should be displayed, confirming that FastDFS, Nginx, and cpolar are correctly integrated.

This end‑to‑end guide provides all necessary commands, configuration edits, and troubleshooting tips for deploying a distributed file service on a single Linux machine and exposing it securely to the internet.

backendDeploymentLinuxNginxfastdfsfile storagecpolar
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.