NGINX, First Deployment of Violence Interpretation

  centos, linux, nginx, php



This chapter is based on Centos 7.x system explanation.

This chapter explains the operation of NGINX when the project is deployed online. Some children’s shoes are installed on the Internet like LNMP on Baidu. They follow the orders one by one. If they don’t make a mistake, it’s ok. Once they make a mistake, they will be in a daze. This is irresponsible behavior towards oneself and the code. This chapter takes you to install NGINX “seriously”.


Don’t look for the source package of NGINX at random. A good NGINX website is there. Why blindly search?

Source package download address: ….


  • Mainline Version mainline version is also a test version of the development version. Don’t download it if you don’t have enemies with yourself.
  • Stable version stable version, general download in stable version to find it
  • Legacy versions Previous Versions

In fact, there are not too many requirements for the version, it is ok to download the stable version, each version is divided into. gz source package and. exe windows installation package, will you download the game and not download a compression package?

Many people struggle with which installation package is better, now I’ll tell you.


Usr’s full name in history is user (User Directory), but that’s not what it means now. In a word, no one will die if we put it here.


Wget is simpler than eating. can you understand?


Then began to download, download understand not to understand? Have you ever downloaded a game?


After downloading/usr/srcThere is a nginx-1.14.0.tar.gz’s shrink-wrapped bag under the catalogue. Then there is the order to brush. Roll up your sleeves and do it.


Tar decompression command

参数 说明
-z 专门解压gzip压缩的,没看到压缩包最后是.gz嘛
-x 解压
-v 解压过程,就是解出来啥文件
-f 指向文件,一定得放最后
tar -zxvf  nginx-1.14.0.tar.gz

The next step was to decompress kaka, and then come out with some unreadable files.


Where are you at this time/usr/srcThere is one in the cataloguenginx-1.14.0Folder

nginx-1.14.0   nginx-1.14.0.tar.gz


The directory is installed now, don’t Baidu or Google, the official website document is so clear what’s the use of doing that extra work. Primary school English can be understood. …, slide to the bottom, the official website gives a demo


This is how it is installed. If you don’t want to know about these configurations, you can do it completely.


Yes, there is no need to add anything. Nine letters end the battle. Why don’t you need to add parameters? Because many parameters of nginx have default values.

参数 默认 注释
–prefix=path /usr/local/nginx nginx安装路径
–sbin-path=path prefix/sbin/nginx nginx命令路径
–modules-path=path prefix/modules nginx模块路径
–conf-path=path prefix/conf/nginx.conf nginx配置文件路径
–error-log-path=path prefix/logs/error.log nginx默认日志目录

Execute. /configure

checking for OS
 + Linux 3.10.0-514.26.2.el7.x86_64 x86_64
 checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
 checking for gcc -pipe switch ... found
 checking for -Wl,-E switch ... found
 checking for gcc builtin atomic operations ... found
 checking for C99 variadic macros ... found
 checking for gcc variadic macros ... found
 checking for gcc builtin 64 bit byteswap ... found
 checking for unistd.h ... found
 checking for inttypes.h ... found
 checking for limits.h ... found
 checking for sys/filio.h ... not found
 checking for sys/param.h ... found
 checking for sys/mount.h ... found
 checking for sys/statvfs.h ... found
 checking for crypt.h ... found
 checking for Linux specific features
 checking for epoll ... found
 checking for EPOLLRDHUP ... found
 checking for EPOLLEXCLUSIVE ... not found
 checking for O_PATH ... found
 checking for sendfile() ... found
 checking for sendfile64() ... found

Configure is a checking tool, the above direct result is very clear, all kinds of checking, testing environment support? Are all the dependencies installed? After the test is successful, you can enter the next step, otherwise you will still be prompted that xxx does not exist, xxx does not support, etc.

make && make install

Make is a compilation tool, you just remember to be a compilation tool, the compilation process output

cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
 -o objs/src/core/nginx.o \
 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
 -o objs/src/core/ngx_log.o \
 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
 -o objs/src/core/ngx_palloc.o \
 cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
 -o objs/src/core/ngx_array.o \
 cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
 test -d '/usr/local/nginx/logs' \
 || mkdir -p '/usr/local/nginx/logs'
 test -d '/usr/local/nginx/logs' \
 || mkdir -p '/usr/local/nginx/logs'
 test -d '/usr/local/nginx/html' \
 || cp -R html '/usr/local/nginx'
 test -d '/usr/local/nginx/logs' \
 || mkdir -p '/usr/local/nginx/logs'
 Make[1]: Leave directory "/usr/src/nginx-1.14.0"

At last, he copied some necessary files to the specified directory, by which time the installation of nginx was basically completed.


If only this command was executed


The directory of nginx is

 cert  client_body_temp  conf  fastcgi_temp  html  logs  proxy_temp  sbin  scgi_temp  uwsgi_temp

All configurations explained below are innginx.confInternal progress

Modify the default pointing directory

Cancels the default pointing resolution directoryhtmlJust comment it out directly. In general, I will point to the project directory/var/wwwGenerally pointed to in the virtual host file

Avoid pan-analysis

Some people will always resolve domain names to the wrong address or maliciously to your server. Such people must be severely punished.

server {
 listen       80  default_server;
 server_name  _;
 return       403;

Minutes to block him

Add virtual host

Do not write all the configuration files of the virtual host into nginx.conf
In general, I will set up a server directory at the same level as nginx.conf

include /usr/local/nginx/conf/server/*.conf;

Configure Gzip compression …

Add SSL support …

Turn on logging …

Turn on load balancing …

Turn on reverse proxy …

Set permissions

It is better to set the nginx command to allow root users or your company’s operations to execute, and the unprovoked nginx -s stop can’t stand it.

Official website document

Nginx’s official website is the most concise and detailed document I feel the document has written. The detailed addresses of each part are listed below

Thank you

Thank you for seeing here. My language in this article is too extreme. I hope I can forgive you. I hope this article can help you. If you have any questions, please leave a message in the comments section. Thank you

Don’t be afraid of English, primary school English level can understand, everything comes from persistence