Author: JackTian
micro-channel public number: IT's Jiege trip (ID: Jake_Internet)
Series Guide
- LAMP series of tutorials (1) | Explain the deployment of HTTPD service in Linux environment
- LAMP series tutorials (2) | How to deploy AWStats analysis system to monitor Web sites in a Linux environment?
- LAMP series of tutorials (3) | An article to understand HTTPD service access control
- LAMP series of tutorials (4) | MySQL database system (1)
- LAMP tutorial series (5) | MySQL database system (2)-basic operations of SQL statements
- LAMP series of tutorials (6) | MySQL database system (3)-database user authorization
- LAMP series tutorial (7) | MySQL database system (4)-database backup and recovery
- LAMP series of tutorials (8) | Take you easy to play with LAMP website architecture platform (1)
- LAMP Series Tutorials (9) | LAMP Architecture Application Case-Deploy PHPMyAdmin System (2)
1. What is Nginx?
Nginx is a high-performance HTTP and reverse proxy web server. It also provides IMAP / POP3 / SMTP services. It was developed by Igor Sesoyev for the second most visited Rambler.ru site in Russia, the first The public version 0.1.0 was released on October 4, 2004. It is characterized by less memory, strong concurrency, developed specifically for performance optimization, stability and low system resource consumption, and high processing capabilities for HTTP concurrent connections. Supports up to 50,000 concurrent connections for a single machine.
So, in fact, the concurrency capability of Nginx performs better in the same type of web server. In the actual environment, if we use Nginx, it may be the following architecture diagram of this scenario. In fact, in the following architecture diagram, the Nginx server can be directly understood as a load balancing server or reverse proxy server, so when the client sends a request to the Nginx server, the Nginx server needs to configure its rules by The request from the client is forwarded to the back-end LAMP, Tomcat, and LNMP.
2. Why use Nginx?
As a web server
compared to Apache, Nginx uses fewer resources and supports more concurrent connections. In the case of high concurrency, Nginx is a substitute for the Apache server. Nginx as a load balancing server internally supports Rails and PHP programs for external services, as well as an HTTP proxy server for external services, written in C language, regardless of system resource overhead The CPU usage efficiency is still much better than Perlbal.
Nginx configuration is simple, and Apache is complex.
Nginx is easy to start. It can almost run 7*24 hours. Even if it is not restarted for a long time, the software version can be upgraded without interruption. The static processing performance is better than Apache is more than 3 times higher. Nginx needs to be used in conjunction with other backends. Apache has simpler support for PHP and has more components than Nginx.
The core point
Nginx is asynchronous, multiple connections can correspond to one process;
Apache is a synchronous multi-process model, one connection corresponds to one process;
Areas of expertise
Nginx is suitable for front-end processing of static requests;
Apache is suitable for back-end processing of dynamic requests;
Three, Nginx installation and
installation support software
The configuration and operation of Nginx need the support of pcre and zlib software packages. The development packages of these softwares need to be installed for the corresponding libraries and header files to ensure the smooth installation of Nginx.
# yum -y install pcre-devel zlib-devel
Create running users and groups
The Nginx service program runs as noboby by default. It is recommended that you create a new user account to more accurately control access permissions, increase flexibility, and reduce security risks;
# useradd -M -s /sbin/nologin nginx
Download, compile and install
When configuring the Nginx compilation options, set the installation directory to /usr/local/nginx, and set the running user and group to nginx; enable the http_stub_status_module module to support status statistics to facilitate viewing server connection information.
# wget http://nginx.org/download/nginx-1.17.0.tar.gz
# tar zxf nginx-1.17.0.tar.gz
# cd nginx-1.17.0
# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
# make && make install
Create a link file for the main program Nginx
# ln -s /usr/local/sbin/nginx /usr/local/sbin/
# ls -l /usr/local/sbin/nginx
lrwxrwxrwx. 1 root root 21 6月 4 07:31 /usr/local/sbin/nginx -> /usr/local/sbin/nginx
After installation, enter the default installation path to the sbin directory, and execute nginx to start;
# cd /usr/local/nginx/sbin/
# pwd
/usr/local/nginx/sbin
# ./nginx
# nginx
Monitor the status of the Nginx program
# netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 53816/nginx
After listening to the port, directly access the Nginx address in the browser. When the browser sees the following page, it means that Nginx has been installed successfully.
Use Nginx service script
to write Nginx service script, use chkconfig and service tools for unified management;
#!/bin/bash
# chkconfig: 2345 99 20
# description: Nginx Server Control Scripts shell
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
if [ -f $PIDF ]; then
echo "Nginx is running.. Start it is error"
else
$PROG
fi
;;
stop)
if [ -f $PIDF ]; then
kill -s QUIT $(cat $PIDF)
rm -rf $PIDF
else
echo "Nginx is stopping .. Stop it is error"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
if [ -f $PIDF ]; then
kill -s HUP $(cat $PIDF)
else
echo "Nginx is stopping . reload it is error"
fi
;;
status)
if [ -f $PIDF ]; then
echo "Nginx is running"
else
echo "Nginx is stopping"
fi
;;
*)
echo "Usage: $0 (start|stop|restart|reload|status)"
exit 1
esac
exit 0
# chmod +x /etc/init.d/nginx
# chkconfig --add nginx
If you modify the Nginx configuration file, you can load the Nginx configuration file through the ./nginx -s reload command.
# ./nginx -s reload
In summary,
we have introduced the basic concepts of Nginx, why use Nginx, and the installation of Nginx has a preliminary understanding. The following articles will continue to introduce forward proxy, reverse proxy, load balancing and building LNMP architecture; today we will introduce Here, if you have any questions, please leave a message for discussion.