“This is the 18th day of my participation in Gwen Challenge.

This article is the first in a series of basic Nginx applications. The next few days will cover some basic Nginx applications.

Release notes

Common versions fall into four camps

Nginx open source edition

nginx.org/

Nginx Plus Business Edition

www.nginx.com

openresty

openresty.org/cn/

Tengine

tengine.taobao.org/

Nginx installation

download

Nginx.org/en/download…

Compile the installation

./configure --prefix=/usr/local/nginx

make

make install
Copy the code

If a warning or error occurs

Install perl library

yum install -y pcre pcre-devel
Copy the code

./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.

Install zlib library

yum install -y zlib zlib-devel
Copy the code

./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> option.

Multiple version conflict

If there are multiple version errors, use the prompt message to resolve!

Start the Nginx

Go to the /usr/local/nginx/sbin directory

Start the

./nginx
Copy the code

A quick stop

./nginx -s stop 
Copy the code

Elegant closed

Complete accepted connection requests before exiting

./nginx -s quit
Copy the code

Reload configuration

./nginx -s reload
Copy the code

Verify that the configuration file is correct

./nginx -t 
Copy the code

Check the version

./nginx -v
Copy the code

View Nginx information

The installed Modules are displayed

./nginx -V
Copy the code

About the Firewall

Centos7 and Centos6 commands are different!

Disabling the Firewall

systemctl stop firewalld.service
Copy the code

Do not enable the firewall upon startup

systemctl disable firewalld.service
Copy the code

Release port

firewall-cmd --zone=public --add-port=80/tcp --permanent
Copy the code

Restarting the Firewall

firewall-cmd --reload
Copy the code

Install as system service

Creating a service script

Note the path address of the script content!

vi /usr/lib/systemd/system/nginx.service
Copy the code
[Unit]
Description=nginx -  web server
After=network.target remote-fs.target nss-lookup.target
  
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target
Copy the code

Reload the system service

systemctl daemon-reload
Copy the code

Start the service

systemctl start nginx.service
Copy the code

Powered up

systemctl enable nginx.service
Copy the code

conclusion

This article introduces the basic installation of Nginx, the class libraries that you rely on during the installation, and the solutions to the errors that occur during the installation. Next introduced the firewall problem, Nginx service installation into the system service command. The next article introduces the basic application of Nginx combat second article.

Welcome everyone to pay attention to the public account (MarkZoe) to learn from each other and communicate with each other.