The background,
Recently I have been working on my own projects using Nginx, so to install nginx on Centos7, here are the installation steps.
Basic concepts and application scenarios
1. What is Nginx
Nginx is a high performance HTTP server/reverse proxy server and E-mail (IMAP/POP3) proxy server developed using C language. Developed by Russian programmer Igor Sysoev, Nginx was officially tested to support up to 50,000 concurrent links with very low CPU, memory and other resource consumption.
2. Application scenarios of Nginx
1). HTTP server. Nginx is an HTTP service that can provide HTTP services independently. Can do web static server.
2). Virtual host. Can be realized in a server virtual out of multiple websites. For example, the virtual host used by personal websites.
3). Reverse proxy, load balancing. When the number of visits to the website reaches a certain level, a single server cannot meet the user’s request, you need to use multiple server cluster can use Nginx as a reverse proxy. In addition, multiple servers can evenly share the load, so that a server is not idle due to the high load of a server downtime.
Three, installation steps
1. Check and install required dependent software
1).gcc: Nginx compilation depends on the GCC environment
Yum install GCC -C ++
2).pcre:(Perl Compatible Regular Expressions) is a Perl library that includes perl-compatible Regular expression libraries. Nginx’s HTTP module uses PCRE to parse regular expressions.
Yum install -y pcre pcre-devel
3).zlib: This library provides a variety of compression and decompression methods. Nginx uses Zlib to gzip the contents of HTTP packages.
Yum install -y zlib zlib-devel
4). Openssl: a powerful Secure Socket layer cryptographic library that includes major cryptographic algorithms, common key and certificate encapsulation management functions, and SSL protocols, and provides rich applications for testing and other purposes. Nginx supports not only HTTP but ALSO HTTPS (that is, HTTP over SSL).
Yum install -y openssl openssl-devel
2. Download the nginx source package
Wget download command: http://nginx.org/download/nginx-1.12.0.tar.gz
3. Decompress the source package and enter
1). Decompress: tar -zxvf nginx-1.12.0.tar.gz
2). Go to the uncompressed folder: CD nginx-1.12.0
/configure –help ()
./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 \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgiCopy the code
Note: Before installing nginx, you need to manually create the specified nginx folder, namely /var/temp, /var/temp/nginx, /var/run/nginx/ folder
5. Compile and install
Command: make && make install
Run the /usr/local/nginx command to check whether the conf, sbin, and HTML folders exist. If yes, the installation is successful
Four, basic use
1. Start the nginx
1). Go to the installation directory
cd /usr/local/nginx/sbin/
2.)
./nginx
[emerg] open() “/var/run/nginx/nginx.pid” failed (2: No such file or directory)
If the nginx folder does not exist in /var/run, create a new folder
4). See if start: ps – ef | grep nginx
If the master and worker processes exist, the startup is successful
/nginx to start nginx, where -c can specify the loaded nginx configuration file, as follows:
./nginx -c /usr/local/nginx/conf/nginx.conf
If -c is not specified, nginx loads the conf/nginx.conf file on startup by default. The address of this file can also be specified when nginx is compiled and installed./configure parameter (–conf-path= pointing to the configuration file (nginx.conf))
2. Stop
1). Kill (not recommended)
kill -9 processId
2). Quick stop
cd /usr/local/nginx/sbin && ./nginx -s stop
This method is equivalent to finding the Nginx process ID and then executing the kill command to forcibly kill the process
3). Complete stop (recommended)
cd /usr/local/nginx/sbin && ./nginx -s quit
The stop step in this mode is to stop the Nginx process after it finishes processing tasks
3. Restart and reload the configuration
1. Stop and start (recommended)
./nginx -s quit && ./nginx
2. Reload the configuration file./ nginx-s reload
4. Test
Nginx is installed successfully, and nginx can be accessed via IP address:
“Recommended”
【Pay attention to my】
www.cnblogs.com/hafiz