NGINX, First Deployment of Violence Interpretation

  centos, linux, nginx, php

clipboard.png

Preface

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”.

download

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

Source package download address:http://nginx.org/en/download ….

clipboard.png

  • 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/src

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  http://nginx.org/download/nginx-1.14.0.tar.gz

Wget is simpler than eating. can you understand?

clipboard.png

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

Installation

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.

unzip

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.

nginx-1.14.0/
 nginx-1.14.0/auto/
 nginx-1.14.0/conf/
 nginx-1.14.0/contrib/
 nginx-1.14.0/src/
 nginx-1.14.0/configure
 nginx-1.14.0/LICENSE
 nginx-1.14.0/README
 nginx-1.14.0/html/
 nginx-1.14.0/man/
 nginx-1.14.0/CHANGES.ru
 nginx-1.14.0/CHANGES
 nginx-1.14.0/man/nginx.8
 nginx-1.14.0/html/50x.html
 nginx-1.14.0/html/index.html
 nginx-1.14.0/src/core/
 nginx-1.14.0/src/event/
 nginx-1.14.0/src/http/
 nginx-1.14.0/src/mail/
 nginx-1.14.0/src/misc/
 nginx-1.14.0/src/os/
 nginx-1.14.0/src/stream/
 nginx-1.14.0/src/stream/ngx_stream_geo_module.c
 nginx-1.14.0/src/stream/ngx_stream.c
 nginx-1.14.0/src/stream/ngx_stream.h
 nginx-1.14.0/src/stream/ngx_stream_limit_conn_module.c
 nginx-1.14.0/src/stream/ngx_stream_access_module.c
 ......

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

./configure

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.http://nginx.org/en/docs/conf …, slide to the bottom, the official website gives a demo

./configure
 --sbin-path=/usr/local/nginx/nginx
 --conf-path=/usr/local/nginx/nginx.conf
 --pid-path=/usr/local/nginx/nginx.pid
 --with-http_ssl_module
 --with-pcre=../pcre-8.41
 --with-zlib=../zlib-1.2.11

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

./configure

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 \
 src/core/nginx.c
 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 \
 src/core/ngx_log.c
 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 \
 src/core/ngx_palloc.c
 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 \
 src/core/ngx_array.c
 ....
 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.

Configuration

If only this command was executed

./configure

The directory of nginx is

/usr/local/nginx
 -----------
 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

http://nginx.org/en/docs/http …

Add SSL support

https://segmentfault.com/a/11 …

Turn on logging

https://segmentfault.com/a/11 …

Turn on load balancing

https://segmentfault.com/a/11 …

Turn on reverse proxy

https://segmentfault.com/a/11 …

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