Ngix installation in fastfds Ubuntu 20 and accessing files on fastDFS through ngix

The main purpose of installing Nginx as a server is to enable the client to access the uploaded files in HTTP. In addition, the Nginx module for installing FastDFS later also requires an Nginx environment  

Nginx only needs to be installed on the server where the StorageServer is located to access files. Because I have a single machine here, TrackerServer and StorageServer are on the same server.

I What is Ngix?

Nginx("engine x") is a high-performance Web and SMTP proxy server developed by Igor Sysoev, a Russian programmer. It is also an IMAP/POP3/SMTP proxy server.

In the case of high connection concurrency, Nginx is a good substitute for Apache server. Because of its small memory occupation, fast startup, high concurrency and strong ability, it is widely used in Internet projects.

1) What is forward agent?

Due to the firewall, we can't directly access Google, so we can use VPN to realize it. This is a simple example of forward proxy. Here you can find that the forward proxy "proxy" is the client, and the client knows the target, but the target does not know that the client is accessed through VPN.

2) What is reverse proxy

When we visit Baidu on the Internet, we will actually forward and proxy to the intranet. This is the so-called reverse proxy, that is, the "proxy" of the reverse proxy is the server side, and this process is transparent to the client  

Reference: Ngix Chinese document

3) Ngix action:

  1. Reverse proxy,

   2. Dynamic and static resources are separated. Static resources are put on Nginx, managed by Nginx, and dynamic requests are forwarded to the back end

   3. IP access control (black and white list)

   4. cache

II Ngix installation  

1) Environment required for installing nginx

 1. gcc installation

Here is ubuntu 20(centos). Please refer to ), install the compiling environment gcc g + + development library, and the following commands:

apt-get install build-essential
apt-get install libtool

2. Generally, we need to install PCRE and zlib first. The former is for rewriting and rewriting, and the latter is for gzip compression.

1. Select source directory
It can be any directory, and / usr/local/src is selected in this article  

cd /usr/local/src

2. Install PCRE Library Download the latest PCRE source code package, and use the following command to download, compile and install the PCRE package:

cd /usr/local/src
tar -zxvf pcre-8.44.tar.gz
cd pcre-8.44
make install

3. Install zlib Library Download the latest zlib source code package, and use the following command to download, compile and install the zlib package:

cd /usr/local/src
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
make install

4. Install ssl  

cd /usr/local/src
tar -zxvf openssl-1.1.1g.tar.gz

5. Install nginx

There are generally two versions of Nginx, namely, stable version and development version. You can choose one of these two versions according to your purpose. The following are the detailed steps to install Nginx in / usr/local/nginx Directory:

cd /usr/local/src
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
make install

6. Start
Make sure that port 80 of the system is not occupied by other programs. Run the / usr/local/nginx/nginx command to start Nginx

netstat -ano|grep 80

If the result cannot be found, execute it. If there is a result, ignore this step (sudo must be used to start under ubuntu, otherwise it can only be run in the foreground)

cd /usr/local/nginx/sbin/

Open the browser to access the IP of this machine. If the browser appears Welcome to nginx! It means that Nginx has been installed and run successfully.

At this point, nginx is installed  

7. Other orders

# ./nginx -s stop
# ./nginx -s quit
# ./nginx -s reload

8. Set startup

vi /etc/init.d/nginx

set -e
DESC="nginx daemon"

# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0

d_start() {
        $DAEMON || echo -n " already running"

d_stop() {
        $DAEMON –s quit || echo -n " not running"

d_reload() {
        $DAEMON –s reload || echo -n " could not reload"

case "$1" in
    echo -n "Starting $DESC: $NAME"
    echo "."
    echo -n "Stopping $DESC: $NAME"
    echo "."
    echo -n "Reloading $DESC configuration..."
    echo "reloaded."
    echo -n "Restarting $DESC: $NAME"
# Sleep for two seconds before starting again, this should give the
# Nginx daemon some time to perform a graceful stop.
    sleep 2
    echo "."
    echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
    exit 3
exit 0

Script authorization

chmod +x /etc/init.d/nginx

Configure self start:

sysv-rc-conf nginx on 

sysv-rc-conf --list nginx
root@iZ8vbeeelmyzkhxvdqblbyZ:~# sysv-rc-conf --list  nginx 
nginx        2:on	3:on	4:on	5:on

View nginx version:

root@iZ8vbeeelmyzkhxvdqblbyZ:~# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.18.0
built by gcc 9.3.0 (Ubuntu 9.3.0-10ubuntu2) 
configure arguments:

III Test access to files on fastDFS:

1) Modify nginx conf

vi /usr/local/nginx/conf/nginx.conf

If the line is added, the /group1/M00 Map to /home/fastdfs/file/data
location /group1/M00 {
    alias /home/fastdfs/file/data;

# Restart nginx
# /usr/local/nginx/sbin/nginx -s reload

The configuration file code is as follows:

 server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        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;

        location /group1/M00{           # Configure path mapping
                alias /home/fastdfs/file/data;


2) Text files uploaded before browser access:



Tags: FastDFS

Posted by adv on Tue, 03 May 2022 02:45:37 +0300