Centos 7 installation and configuration nginx detailed tutorial, centosng.pdf

Source: Internet
Author: User
Tags openssl library

Centos 7 installation and configuration nginx detailed tutorial, centosng.pdf

Nginx is developed in C language. It is recommended to run on Linux. Of course, you can also install the Windows version. In this article, CentOS 7 is used as the installation environment.

1. Install gcc
To install nginx, you must first compile the source code downloaded from the official website and compile the code based on the gcc environment. If there is no gcc environment, you must install:

yum install gcc-c++

Ii. Install PCRE-devel
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. Therefore, you need to install the pcre Library on linux. pcre-devel is a secondary development library developed using pcre. Nginx also needs this library. Command:

yum install -y pcre pcre-devel

Iii. zlib Installation
The zlib library provides many compression and decompression methods. nginx uses zlib to perform gzip on the http package content. Therefore, you need to install the zlib library on Centos.

yum install -y zlib zlib-devel

4. OpenSSL Installation
OpenSSL is a powerful secure socket-layer cryptographic library that includes major cryptographic algorithms, common keys, certificate encapsulation management functions, and SSL protocols, and provides a wide range of applications for testing or other purposes.
Nginx not only supports the http protocol, but also supports https (that is, transmitting http over the ssl protocol). Therefore, you need to install the OpenSSL library in Centos.

yum install -y openssl openssl-devel
Download from official website

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

2. Use the wget command to download (recommended ).

wget -c https://nginx.org/download/nginx-1.10.1.tar.gz

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

Extract

It is still a direct command:

tar -zxvf nginx-1.10.1.tar.gzcd nginx-1.10.1
Configuration

In fact, in the nginx-1.10.1 version you do not need to configure related things, the default can be. Of course, you can also configure directories by yourself.
1. Use the default configuration

./configure

2. Custom 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: To specify the temporary file directory as/var/temp/nginx, you must create the temp and nginx directories under/var.

Compile and install
makemake 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 stop process is to stop the nginx process after processing the task.
./Nginx-s stop: This method is equivalent to first identifying the nginx process id and then using the kill command to forcibly kill the process.

Query nginx processes:

ps aux|grep nginx
Restart nginx

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

./nginx -s quit./nginx

2. Reload the configuration file:
When nginx. after the conf file is modified, restart nginx to make the configuration take effect. You do not need to stop ngin x and then start nginx to use-s reload to make the configuration take effect in nginx, as shown below:
./Nginx-s reload

After the startup is successful, you can see the following page in the browser:

Auto-start

Add the startup code in rc. local.

vi /etc/rc.local

Add/usr/local/nginx/sbin/nginx
Set the execution permission:

chmod 755 rc.local

Now nginx has been installed, and the start, stop, and restart operations have been completed. Of course, you can also add it as a system service. I will not demonstrate it here.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.