This is the 18th day of my participation in the Gwen Challenge.

What is the Nginx

Nginx (Engine X) is a high-performance HTTP and reverse proxy Web server that also provides IMAP/POP3/SMTP services. In fact, nginx’s concurrent ability is better in the same type of web server. In Mainland China, nginx website users include: Baidu, JINGdong, Sina, netease, Tencent, Taobao, etc.

There are three main usage scenarios for Nginx

  • Static Resource service
    • Services are provided through the local file system
  • Reverse proxy service
    • Ngnix powerful performance
    • The cache
    • Load balancing
  • API service
    • OpenResty

The advantages of Nginx

The composition of Nginx

Nginx binary executable: A file compiled from the source code of each module

Nginx configuration file nginx.conf: controls Nginx behavior

Access. log Records information about each HTTP request

Error. log Error log: Records error information to locate faults

Nginx compilation and installation

Environment to prepare

1. Install dependencies

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
Copy the code

2. Install common tools

yum -y install wget httpd-tools vim
Copy the code

3. Check the firewall status

Systemctl status firewalld or firewall-cmd --stateCopy the code

4. Configure iptables because the firewall is enabled

Install the iptables

yum install iptables-services  
Copy the code

Configure iptables rules

vim /etc/sysconfig/iptables
Copy the code

Commonly used ports 80 and 8080

# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration*filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -a INPUT -p TCP -m state --state NEW -m TCP --dport 80 -jaccept # add -a INPUT -p TCP -m state --state NEW -m TCP --dport 8080 -j ACCEPT # A INPUT -j REJECT -- REJECT -with icmp-host-shell-a FORWARD -j REJECT -- REJECT -with icmp-host-prohibited COMMITCopy the code

Restart to take effect

systemctl restart iptables
Copy the code

Install Nginx

1. Download the Nginx package

Wget HTTP: / / https://www.nginx.org/download/nginx-1.17.7.tar.gzCopy the code

2. Unzip

The tar - ZXVF nginx - 1.17.7. Tar. GzCopy the code

3.Nginx directory structure

drwxr-xr-x. 6 1001 1001 4096 Jun 15 18:53 auto -rw-r--r--. 1 1001 1001 301572 Dec 24 23:00 CHANGES -rw-r--r--. 1 1001 1001 460207 Dec 24 23:00 CHANGES.ru drwxr-xr-x. 2 1001 1001 168 Jun 15 18:53 conf -rwxr-xr-x. 1 1001 1001 2502 Dec 24 23:00 configure drwxr-xr-x. 4 1001 1001 72 Jun 15 18:53 contrib drwxr-xr-x. 2 1001 1001 40 Jun 15 18:53 html -rw-r--r--.  1 1001 1001 1397 Dec 24 23:00 LICENSE drwxr-xr-x. 2 1001 1001 21 Jun 15 18:53 man -rw-r--r--. 1 1001 1001 49 Dec 24 23:00 README drwxr-xr-x. 9 1001 1001 91 Jun 15 18:53 srcCopy the code

4. Compile and install

[root @ centos7 nginx - 1.6.2] #. / configure -- prefix = / usr/local/webserver/nginx - with - http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/ SRC /pcre-8.35 [root@centos7 nginx-1.6.2]# make [root@centos7 nginx-1.6.2]# Make install [root @ centos7 nginx - 1.6.2] #Copy the code

other

Compile parameters

Destination installation directory or path

  • –prefix=/etc/nginx
  • –sbin-path=/usr/sbin/nginx
  • –modules-path=/usr/lib64/nginx/modules
  • –conf-path=/etc/nginx/nginx.conf
  • –error-log-path=/var/log/nginx/error.log
  • –http-log-path=/var/log/nginx/access.log
  • –pid-path=/var/run/nginx.pid (record the ID of the nginx process that started the service)
  • –lock-path=/var/run/nginx.lock

Temporary files retained by Nginx when the corresponding module is executed

  • –http-client-body-temp-path=/var/cache/nginx/client_temp
  • –http-proxy-temp-path=/var/cache/nginx/proxy_temp
  • –http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
  • –http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
  • –http-scgi-temp-path=/var/cache/nginx/scgi_temp

RPM Installation directory

/etc/logrotate.d/nginx
Copy the code
  • Type: Configuration file
  • Purpose: Nginx log rotation, used for log cutting of logrotate service (e.g. log cutting by day)
/etc/nginx /etc/nginx/nginx.conf /etc/nginx/conf.d /etc/nginx/conf.d/default.conf
Copy the code
  • Type: directory, configuration file
  • Nginx master configuration file

The/etc/nginx/nginx. Conf is the main configuration file, read when nginx start first, when there is no change, will read the/etc/nginx/conf. D/default. Conf (installation is loaded by default).

/etc/nginx/fastcgi_params /etc/nginx/uwsgi_params /etc/nginx/scgi_params
Copy the code
  • Type: Configuration file
  • Function: CGI configuration related, FastCGI configuration
/etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/win-utf
Copy the code
  • Type: Configuration file
  • Function: Code conversion map conversion file
/etc/nginx/mime.types
Copy the code
  • Type: Configuration file
  • Function: Sets the mapping between the HTTP ContentType and the extension

Nginx needs to edit this file when dealing with unrecognized extensions and file types

/usr/lib/systemd/system/nginx-debug.service /usr/lib/systemd/system/nginx.service /etc/sysconfig/nginx /etc/sysconfig/nginx-debug
Copy the code
  • Type: Configuration file
  • Function: Used to configure the system daemon manager management mode
/usr/lib64/nginx /etc/nginx/modules
Copy the code
  • Type: Directory
  • Function: Nginx module directory
/usr/sbin/nginx /usr/sbin/nginx-debug
Copy the code
  • Type: command
  • Nginx service startup management terminal command
The/usr/share/doc/nginx - 1.6.2 / usr/share/doc/nginx - 1.6.2 / COPYRIGHT/usr/share/man/man8 / nginx. 8. GzCopy the code
  • Type: file, directory
  • Nginx manual and help files
/var/cache/nginx
Copy the code
  • Type: Directory
  • Nginx cache directory

Nginx processing can be used as a proxy, but also as a caching service

/var/log/nginx
Copy the code
  • Type: Directory
  • Nginx log directory