1024programmer Nginx Nginx Series Two (Installation and Startup and nginx.conf Configuration Analysis)

Nginx Series Two (Installation and Startup and nginx.conf Configuration Analysis)

The installation of Nginx is relatively simple. The installation provided under Windows is a zip package.

It can be installed after decompression directly, and the nginx server can be started by running nginx.exe under its installation directory

For the linux version, you need to execute the following command

For the above commands, ./configure is a tool for generating makefiles in linux, and the general commands are:

./configure

–prefix=/home/vf/usr/local/nginx

–with-http_gzip_static_module

–with-http_ssl_module

–with-http_stub_status_module

–with-http_sub_module

–with-http_realip_module

            –with-http_realip_module –add-module=/home/vf/usr/local/nginx-sticky-module  

The more important one is –prefix, which is a prefix that represents the installation location of the program.

The follow-up is to pass several key parameters. For these parameters, the configuration file is modified when nginx is installed. For details, please refer to the configuration document of Nginx.

After the ./configure tool, the makefile is generated, which is the specified file for linux source code installation, and then make is executed.

The make command compiles according to the makefile and does not install it. There may be some errors in this step. Compare

An obvious error is the absence of the PCRE library, which needs to be installed again through yum or apt-get:

./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= option.

[aps@localhost nginx-1.8.0]$ yum -y install pcre-devel

===== “pcre-devel is missing this library file

After installation, it is not much different from the startup of windows. It also runs the nginx command, but nginx is installed under the sbin directory, which is different from the location of the windows directory.

Executing ./nginx will load the configuration file of conf/nginx.conf by default and read it. If you don’t want to use this configuration, you can specify it through the -c parameter:

The startup of Nginx is very simple, but if it is closed, there is no corresponding command. It responds based on the signal mechanism of the operating system.

You need to input signals to this Nginx through the kill parameter, and the signal types are:

The general shutdown method is ps -ef | grep nginx, find the pid of the corresponding nginx process, and then send a signal through kill xxx:

Next, focus on the nginx.conf configuration file. Overall, nginx.conf is divided into several parts:

The whole is divided into 4 parts:

1. nginx global configuration:

The so-called global configuration is the user, group (operating system) to which nginx belongs,

The specified number of worker processes, theis the number of worker processes in the Nginx architecture.

Wrong log location has nothing to say,

The storage location of the pid is very interesting. You can see that if the above-mentioned nginx is closed, you have to ps -ef | grep nginx to find the corresponding pid number every time, and then execute kill to directly send signals to this number. It is very troublesome, so the function of this pid file is to start nginx, automatically detect the current nginx process number, and then fill the content into this nginx.pid file. At this time, we can directly close it through the following command. Very convenient:

The number of file descriptors is also an important parameter, because in Linux, the number of fd files that each corresponding process can control is limited to 1024. Although we can set it through ulimit, we need to modify the entire operation The limitation of the system is more troublesome. Here we provide the configuration of directly modifying the file descriptor (in essence, it is also done by calling the system call of the linux system)

2. IO model configuration:

As mentioned in the first lecture, the network IO model of epoll is used in Nginx, and this configuration is configured here.

worker_connections is to set the number of connections currently allowed.

3. http related configuration:

There is nothing to say about the http configuration, just some attributes of the http-related protocol format and some attributes of the socket,

The attributes of the http protocol format are character set, mime type, charset. upload, etc.,

Several socket attributes are still useful:

sendfile:j is a system call, which saves a few steps of copying operations, directly from the user mode buffer to the network card buffer, skipping the process of the kernel buffer, keepalive_timeout: is also a relatively important attribute, let’s study it first What is keepalive:

A complete page requires many requests to complete, such as pictures, JS, CSS, etc. If each HTTP request needs to create and disconnect a TCP, this overhead is completely unnecessary. After enabling HTTP Keep-Alive, it can be restored With the existing TCP connection, the current request has been responded to, the server does not close the TCP connection immediately, but waits for a period of time to receive the second request that the browser may send, usually after the browser returns the first request The second request will be sent immediately. If there is only one connection at a time, the more requests processed by the same TCP connection, the more consumption of TCP establishment and shutdown can be saved by enabling KeepAlive. Of course, multiple links are usually enabled to request resources from the server, but after Keep-Alive is turned on, the loading speed of resources can still be accelerated. After HTTP/1.1, Keep-Alive is enabled by default, and the Connection option is added in the HTTP header field. When it is set to Connection:keep-alive, it means open, and when it is set to Connection:close, it means it is closed.

nginx’s keepalive_timeout (Apache’s KeepAliveTimeout is the same), this keepalive_timout time value means:

A tcp connection generated by http needs to be held for keepalive_timeout seconds after the last response is transmitted before closing the connection.

tcp_nodelay: Explained in vernacular, the amount of small packets is very large. If a packet is sent one by one, it is likely to occupy a tcp every time. If the amount is large, the bandwidth may be occupied, so the tcp protocol will be optimized by default. , Save to a certain level before posting, although there is a slight delay for some time (not visible to the naked eye), but minimizing network congestion corresponds to this attribute.

4. Virtual host Server related configuration:

Server can be understood as corresponding to the Host in tomcat, and n applications can be run in one Nginx, and each application is a Server.

As shown in the figure above, the port is 80, the server_name attribute is the domain name, which is www.yourdomain.com, and the index is the homepage.

The location of root is the root directory of the html application. From this level, visit down. The following are some log settings, and there is another configuration based on IP

Basically the same:

The above access_log is the access log, and this tomcat also records which pages are accessed by which IP segment.

As can be seen from the above configuration, Nginx is just a loading container for html pages, you provide the page, it helps you access, some JSP, PHP and other page interpretation scripts

Nginx itself does not provide these functions. It is necessary to install and develop Nginx plug-ins, interpret them, compile them into html, and then access them externally.

Subsequent content will focus on topics such as how to optimize Nginx, how to integrate PHP, and how to develop Nginx plug-ins.

�One Nginx can run n applications, and each application is a Server.

As shown in the figure above, the port is 80, the server_name attribute is the domain name, which is www.yourdomain.com, and the index is the homepage.

The location of root is the root directory of the html application. From this level, visit down. The following are some log settings, and there is another configuration based on IP

Basically the same:

The above access_log is the access log, and this tomcat also records which pages are accessed by which IP segment.

As can be seen from the above configuration, Nginx is just a loading container for html pages, you provide the page, it helps you access, some JSP, PHP and other page interpretation scripts

Nginx itself does not provide these functions. It is necessary to install and develop Nginx plug-ins, interpret them, compile them into html, and then access them externally.

Subsequent content will focus on topics such as how to optimize Nginx, how to integrate PHP, and how to develop Nginx plug-ins.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/nginx-series-two-installation-and-startup-and-nginx-conf-configuration-analysis/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索