Centos builds image server with Nginx and vsftpd

1. Introduction to Nginx

nginx - Alchetron, The Free Social Encyclopedia

Nginx (engine x) is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP server. Nginx was developed by Igor Sesoyev for the second most visited site in Russia, Rambler.ru (Russian: Рамблер), and the first public version 0.1.0 was released on October 4, 2004.
It releases the source code under a BSD-like license and is known for its stability, rich feature set, sample configuration files, and low consumption of system resources. On June 1, 2011, nginx 1.0.4 was released.
Nginx is a lightweight web server/reverse proxy server and email (IMAP/POP3) proxy server distributed under a BSD-like protocol. Its characteristics are that it occupies less memory and has strong concurrency capabilities. In fact, the concurrency capabilities of nginx are indeed better among web servers of the same type. The users of nginx websites in mainland China include: Baidu, JD.com, Sina, NetEase, Tencent, Taobao, etc.

This article mainly introduces Centos to build a picture server through nginx and vsftpd. Friends who need it can refer to the following

2. Nginx installation

Nginx official website
Ngxin download address

2.1 , nginx installation environment

yum  install -y  gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

Here are some brief introductions

nginx is developed in C language, it is recommended to run on linux, this tutorial uses Centos 7.2 as the installation environment.

# cat /etc/redhat-release
# uname -a

To install nginx, you need to compile the source code downloaded from the official website first, and the compilation depends on the gcc environment. If there is no gcc environment, you need to install gcc:

yum install gcc-c++

PCRE (PerlCompatible Regular Expressions) is a Perl library that includes a perl-compatible regular expression library. The http module of nginx uses pcre to parse regular expressions, so the pcre library needs to be installed on linux.

yum install -y pcre pcre-devel

Note: pcre-devel is a secondary development library developed with pcre. This library is also required by nginx.

The zlib library provides many ways to compress and decompress. nginx uses zlib to gzip the contents of the http package, so the zlib library needs to be installed on linux.

yum install -y zlib zlib-devel

OpenSSL is a powerful secure socket layer cryptographic library, including major cryptographic algorithms, commonly used key and certificate encapsulation management functions and SSL protocols, and provides rich applications for testing or other purposes.

Nginx supports not only the http protocol, but also https (that is, transmitting http over the ssl protocol), so you need to install the openssl library in linux.

yum install -y openssl openssl-devel

2.2, download Nginx, compile and install

The Nginx official website provides three types of versions
- Mainline version: Mainline is the version that Nginx is currently working on, which can be said to be the development version
- Stable version: the latest stable version, the version recommended in the production environment
- Legacy versions: the legacy legacy version stable

The latest stable version is nginx-1.12.1

The demo is using nginx-1.13.4

1. Download Nginx

# wget http://nginx.org/download/nginx-1.13.4.tar.gz

2. Unzip:

tar -zxvf nginx-1.13.4.tar.gz

3. Enter the root directory of nginx:

cd nginx-1.13.4

4. configure configuration

Query detailed parameters

./configure --help 

Here only configure the installation directory and other parameters by default

 ./configure --prefix=/usr/local/nginx 

Screenshot of successful configuration

5. Compile and install

make 
make install

make compile (the process of make is to turn source files written in various languages ​​into executable files and various library files)

make install installation (make install is to copy these compiled executable files and library files to the appropriate place)

After the installation is successful, check the installation directory:

3. Nginx start and stop

3.1 Determine whether the configuration file is correct

cd  /usr/local/nginx/sbin

./nginx -t
或者指定配置文件
./nginx -t -c /usr/local/nginx/conf/nginx.conf

3.2 Start

cd /usr/local/nginx/sbin/
./nginx

Note: Execute ./nginx to start nginx, where -c can specify the loaded nginx configuration file, as follows:

cd /usr/local/nginx/sbin/
./nginx -c /usr/local/nginx/conf/nginx.conf

If -c is not specified, nginx will load the conf/nginx.conf file by default when it starts up. The address of this file can also be specified when compiling and installing nginx. The parameter of ./configure (--conf-path= points to the configuration file (nginx.conf) )

Query the nginx process:

27811 is the process id of the nginx master process, and 27812 is the process id of the nginx worker process

3.3 Stop and restart nginx

3.3.1 Stop

Way 1, quick stop:

cd /usr/local/nginx/sbin 
./nginx -s stop 

This method is equivalent to first finding out the nginx process id and then using the kill command to forcibly kill the process.

Method 2, complete stop (recommended):

cd /usr/local/nginx/sbin 
./nginx -s quit 

The stopping step of this method is to stop the nginx process after the processing task is completed.

3.3.2 Restart nginx

Method 1, stop first and then start (recommended):
Restarting nginx is equivalent to stopping nginx first and then starting nginx, that is, executing the stop command before executing the start command.
as follows:

./nginx -s quit 
./nginx 

Method 2, reload the configuration file:
when the nginx configuration file nginx.conf is modified, you need to restart nginx to make the configuration take effect. Use -s reload to make the configuration information take effect in nginx without stopping nginx first and then starting nginx, as follows :

./nginx -s reload 

4. Test Nginx

Nginx is successfully installed, start nginx, and you can access Nginx on the virtual machine. If Nginx is started and other computers cannot access, please set up a firewall

5. FTP installation

Please refer to an article written before to build FTP file service based on CentOS

The FTP image upload and save directory is/data/ftp/pub/img

6. Configure Nginx to access pictures on FTP

6.1 Create Nginx configuration directory

Create the /usr/local/nginx/confNginx configuration directory in the directory conf.dfor the convenience of unified management of Nginx configuration files.

mkdir -p  /usr/local/nginx/conf/conf.d

6.2 Setting up the main configuration file

Set the main configuration file to load all configuration files with the suffix conf in conf.d and enable the log of log_format main

 include conf.d/*.conf;    

6.3 Nginx add image server

Add the file in the /usr/local/nginx/conf/conf.ddirectory img.confand add the following:

server {
    listen       8190;
        error_log  logs/storer_error.log debug;
        access_log logs/storer_access.log main;
        location /img/ {
                #alias /data/ftp/pub/img/;
                root /data/ftp/pub/;
        }
}

Check if the configuration file is correct

../sbin/nginx -t

Start Nginx

 ../sbin/nginx

If it has been started before

 ../sbin/nginx -s reload 

Browser input Nginx access address test
http://10.211.55.4:8190/img/666.jpeg

Recommended reading
Extremely fast development of WeChat public account Based on CentOS
Mysql 5.7.19 Installation and master-slave synchronization configuration details Intranet penetration JDK development environment construction and environment variable configuration




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325846937&siteId=291194637