Home > Java > javaTutorial > body text

JAVA--Example of how to install Nginx server under CentOS

巴扎黑
Release: 2017-08-05 13:59:27
Original
1657 people have browsed it

1. nginx installation environment

nginx is developed in C language and is recommended to be run on Linux. This tutorial uses Centos7 as the installation environment.

1.1 gcc

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

1.2 PCRE

PCRE (Perl Compatible Regular Expressions) is a Perl library, including 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 using pcre. nginx also requires this library.

1.3 zlib

The zlib library provides many compression and decompression methods. 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

1.4 openssl

OpenSSL is a powerful Secure Sockets Layer cryptographic library, including major Cryptographic algorithms, commonly used key and certificate encapsulation management functions and SSL protocols, and provides a wealth of applications for testing or other purposes.

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

yum install -y openssl openssl-devel

2. Compile and install

2.1 Official website download

Download .tar directly. gz installation package

2.2 Unzip


tar -zxvf nginx-1.12.1.tar.gz
cd nginx-1.12.1
Copy after login

2.3 Configuration

Actually in nginx-1.10. In version 1, you don’t need to configure related things, the default is fine. Of course, it is also possible if you want to configure the directory yourself.

1. Use the default configuration (recommended)


./configure
Copy after login

2. Customize the configuration (not recommended)

Note: To specify the temporary file directory as /var/temp/nginx, you first need to create the temp and nginx directories under /var (/var/temp/nginx)


./configure \--prefix=/usr/local/nginx \--conf-path=/usr/local/nginx/conf/nginx.conf \--pid-path=/usr/local/nginx/conf/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/scgi
Copy after login

3. Compile and install


make
make install
Copy after login

After the compilation and installation are completed, you can view the installation path of nginx:


whereis nginx
Copy after login

4. Start and stop nginx


cd /usr/local/nginx/sbin/./nginx 
./nginx -s stop
./nginx -s quit
./nginx -s reload
./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
Copy after login

5. Query nginx process


ps aux|grep nginx
Copy after login

Restart nginx

1. Stop and then start (recommended):

Restarting nginx is equivalent to stopping and then starting, that is, executing first Stop command and then execute start command. As follows:


./nginx -s quit
./nginx
Copy after login

2. Reload the configuration file:

When the nginx configuration file nginx.conf is modified, a restart is required for the configuration to take effect. nginx, use -s reload to make the configuration information effective in nginx without first stopping ngin Corresponding to the IP address of the machine (such as: 192.168.1.121), you can see a page like this:


2.4 Auto-start at boot

That is, in rc.local Just add the startup code.

./nginx -s reload
Copy after login

Add a line to /usr/local/nginx/sbin/nginx


##Set execution permissions:

vim /etc/rc.local
Copy after login
At this point, nginx is installed, and the start, stop, and restart operations are also completed.

The above is the detailed content of JAVA--Example of how to install Nginx server under CentOS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template