Environment required for installation

Nginx yes C language Development, Suggested in Linux Up operation, Of course, Can also be installed Windows Edition, This article uses CentOS
<http://www.linuxidc.com/topicnews.aspx?tid=14> 7 As installation environment.

One. gcc install
install nginx You need to compile the source code downloaded from the official website first, Compile dependency gcc Environmental Science, Without gcc Environmental Science, Installation is required:
yum install gcc-c++
Two. PCRE pcre-devel install
PCRE(Perl Compatible Regular Expressions) It is aPerl library, Include perl Compatible regular expression library.nginx Of
http Module usage pcre To parse regular expressions, So we need to linux Installation on pcre library,pcre-devel Is used pcre
A secondary development library developed.nginx This library is also required. command:
yum install -y pcre pcre-devel
Three. zlib install
zlib The library provides many ways to compress and decompress, nginx Use zlib Yes http The content of the package gzip , So we need to Centos Installation on zlib
yum install -y zlib zlib-devel
Four. OpenSSL install
OpenSSL Is a powerful secure socket layer password Library, Including the main cryptographic algorithms, Common key and certificate encapsulation management functions and SSL Agreement, And provide rich application programs for testing or other purposes.
nginx Not only support http Agreement, Also support https( That is, inssl Transfer over protocolhttp), So we need to Centos install OpenSSL library.
yum install -y openssl openssl-devel
Download official website

1. Direct download.tar.gz Installation package, address:https://nginx.org/en/download.html

2. Usewget Command Download( Recommend).
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz

I downloaded1.10.1 Edition, This is the current stable version.


Still a direct order:
tar -zxvf nginx-1.10.1.tar.gz cd nginx-1.10.1
To configure

Actually in nginx-1.10.1 You don't need to configure anything in this version, By default. Of course, If you want to configure your own directory, you can.
1. Use default configuration
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
notes: Specify temporary file directory as/var/temp/nginx, Need to/var Create belowtemp andnginx Catalog

Compilation and installation
make make install
Find installation path:
whereis nginx

start-up, Stop itnginx
cd /usr/local/nginx/sbin/ ./nginx ./nginx -s stop ./nginx -s quit ./nginx -s
./nginx -s quit: The stop step in this way is to waitnginx Process processing task completed to stop.
./nginx -s stop: This method is equivalent to finding out firstnginx processid Reusekill Command force kill process.

querynginx process:
ps aux|grep nginx
restart nginx

1. Stop and start( Recommend):
Yes nginx To restart is to stop and then start, That is, execute the stop command before the start command. as follows:
./nginx -s quit ./nginx
2. Reload profile:
When ngin x Profile for nginx.conf After modification, A reboot is required for the configuration to take effect nginx, Use-s reload Don't stop first ngin x Restart
nginx The configuration information can be nginx Enter into force, as follows:
./nginx -s reload

After successful startup, You can see such a page in the browser:

Power on self start

That is, inrc.local Add startup code.
vi /etc/rc.local
Add a row /usr/local/nginx/sbin/nginx
Set execution permission:
chmod 755 rc.local

Come here,nginx That's it, start-up, Stop it, The restart operation is complete, Of course, You can also add as a system service, I'm not going to show it here.