Centos 7 install and configure nginx

The environment required for installation

Nginx is developed in C language. It is recommended to run on Linux. Of course, the Windows version can also be installed. This article uses CentOS 7 as the installation environment.

1. gcc installation 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:

yum install gcc-c++
2. PCRE pcre-devel Install
PCRE (Perl Compatible Regular Expressions) Yes 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. pcre-devel is a secondary development library developed with pcre. nginx also requires this library. Command:

yum install -y pcre pcre-devel
3. zlib Installing
the zlib library provides a variety of compression and decompression methods. nginx uses zlib to gzip the contents of the http package, so the zlib library needs to be installed on Centos.

yum install -y zlib zlib-devel
4. OpenSSL installation
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 on Centos.

yum install -y openssl openssl-devel
official website download

1. Directly download the .tar.gz installation package, address: https://nginx.org/en/download.html

#wget https://nginx.org/download/nginx- 1.12.1.tar.gz

I downloaded version 1.10.1, which is the current stable version.

Decompression is

still a direct command:

#tar -zxvf nginx-1.12.1.tar.gz #cd
nginx-1.12.1
configuration

In fact, in the nginx-1.10.1 version, you do not 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 default configuration

#./configure
2. Customize configuration (not recommended)

./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
Note: Specify the temporary file directory as /var /temp/nginx, you need to create temp and nginx directories under /var

Compile install

#make

make install
Find the installation path:

whereis nginx
start and stop nginx

#cd /usr/local/nginx/sbin/
#./nginx
./nginx - s stop
./nginx -s quit
./nginx -s reload
./nginx -s quit: The stopping step of this method is to stop the nginx process after the processing task is completed.
./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.

To query the nginx process:

ps aux|grep nginx to
restart nginx

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

./nginx -s quit
./nginx
2. Reload the configuration file:
When the configuration file nginx.conf of nginx is modified, you need to restart nginx to make the configuration take effect. Use -s reload without first stopping nginx and restarting nginx can put the configuration information into effect in nginx, as follows:
./nginx -s

After the reload is started successfully, you can see the page like this in the browser:


Self-start after booting

, just add the startup code in rc.local.

#vi /etc/rc.local
Add a line to /usr/local/nginx/sbin/nginx
to set the execution permission:

#chmod 755 rc.local


download Nginx
$yum install nginx

Enable nginx service
$service nginx start

Add boot start
$systemctl enable nginx

Beijing java job search group 145471323

Guess you like

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