Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the HTTP protocol and how many request methods are there in the HTTP protocol?

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

HTTP

HTTP protocol is the abbreviation of Hyper Text Transfer Protocol (Hypertext transfer Protocol). It is a transport protocol used to transfer hypertext from a WWW:World Wide Web server to a local browser. HTTP is a communication protocol based on TCP/IP.

To transfer data (HTML files, image files, query results, etc.).

How http works

1. The working principle of HTTP

The HTTP protocol works on the client-server architecture. As a HTTP client, the browser sends all requests to the HTTP server, the WEB server, through URL.

Web servers include: Nginx,Apache server, IIS server (Internet Information Services) and so on.

After receiving the request, the Web server sends response information to the client.

The default port number for HTTP is 80, but you can also change it to 8080 or another port. There are three points to note for HTTP:

-HTTP is connectionless: connectionless means limiting the processing of only one request per connection. After the server processes the customer's request and receives the customer's reply, it disconnects. Transmission time can be saved in this way.

-HTTP is media independent: this means that any type of data can be sent over HTTP as long as the client and server know how to handle the data content. The client and server specify the appropriate MIME-type content type to be used.

-HTTP is stateless: the HTTP protocol is stateless. Statelessness means that the protocol has no memory ability for transactions. The lack of state means that if the previous information is required for subsequent processing, it must be retransmitted, which may result in an increase in the amount of data transmitted per connection. On the other hand, the server responds faster when it does not need previous information.

2.HTTP protocol communication flow

1/87

Http message structure

Message structure:

HTTP is a client / server-based architecture model that exchanges information through a reliable link and is a stateless request / response protocol.

A HTTP "client" is an application (Web browser or any other client) that connects to the server to reach the service

The purpose of sending one or more HTTP requests by the.

A HTTP "server" is also an application (usually a Web service, such as an Apache Web server or IIS server, etc.) by receiving requests from the client and sending HTTP response data to the client.

HTTP uses uniform resource identifiers (Uniform Resource Identifiers, URI) to transfer data and establish connections.

Client request

The request message that the client sends a HTTP request to the server includes the following format: request line (request line), request header (header), blank line and request data. The following figure shows the general format of the request message.

Server response message

The HTTP response also consists of four parts: the status line, the message header, the blank line, and the response body.

2/87

The following example is a typical example of using GET to pass data: client request:

Connected to www.testpm.cn (47.244.247.240) port 80 (# 0)

GET / hello.txt HTTP/1.1 # request method and version protocol.

User-Agent: curl/7.29.0 # what client does it use to access

Host: www.testpm.cn # hostname, domain name. Host and port number

Accept: / # what file type does it match? "*" is a universal match. Match all types

Server response:

< HTTP/1.1 200 OK #请求返回的状态码 http://jd.com location /a { root /html; if ($host ~* testpm.com ) { rewrite .* http://jd.com permanent; } 40/87 } 例4: http://www.qf.com/a/1.html ==>

Http://jd.com/a/1.html location / a {

Root / html

If ($host ~ * testpm.com) {

Rewrite. * http://jd.com$request_uri permanent

}

}

Example 5: add / after accessing the directory (if there is one after the directory, do not add /)

# http://www.tianyun.com/a/b/c

# $1: / a Compact b

# $2: C

# http://$host$1$2/

Location / a/b/c {

Root / usr/share/nginx/html; index index.html index.hml; if (- d $request_filename) {

Rewrite ^ (. *) ([^ /]) $http://$host$1$2/ permanent

}

}

Example 6:

Http://www.tianyun.com/login/tianyun.html = = > http://www.tianyun.com/reg/login.html?user=tianyun location / login {

Root / usr/share/nginx/html

Rewrite ^ / login/ (. *) .html$ http://$host/reg/login.html?user=$1;

}

Location / reg {

Root / usr/share/nginx/html; index login.html

}

Example 7:

# http://www.tianyun.com/qf/11-22-33/1.html = = > http://www.tianyun.com/qf/11/22/33/1.html location / qf {

Rewrite ^ / qf/ ([0-9] +)-([0-9] +)-([0-9] +) (. *) $/ qf/$1/$2/$3 $4 permanent

}

Location / qf/11/22/33 {root / html

Index 1.html

}

41/87

Set

The set instruction is used to define a variable and assign a value

Application environment: server,location,if

Application example: example 8:

# http://alice.testpm.com = > http://www.testpm.com/alice # http://jack.testpm.com = = > http://www.testpm.com/jack

[root@nginx-server conf.d] # cd / usr/share/nginx/html/ [root@nginx-server html] # mkdir jack alice [root@nginx-server html] # echo "jack.." > > jack/index.html [root@nginx-server html] # echo "alice.." > > alice/index.html

A. DNS implements universal parsing

IN A website IP

Or resolve the domain name host file locally

10.0.105.202 www.testpm.com

10.0.105.202 alice.testpm.com

10.0.105.202 jack.testpm.com

Edit the configuration file:

Server {

Listen 80

Server_name www.testpm.com

Location / {

Root / usr/share/nginx/html

Index index.html index.htm

If ($host ~ * ^ www.testpm.com$) {break

}

If ($host ~ "^ (.) .testpm.com$") {set $user $1

Rewrite. * http://www.testpm.com/$user permanent

}

}

Location / jack {

Root / usr/share/nginx/html; index index.html index.hml

}

Location / alice {

Root / usr/share/nginx/html; index index.html index.hml

}

}

Return

42/87

The return instruction is used to return the status code to the client server,location,if.

Application example:

Example 9: if the file at the end of .sh is accessed, 403 operation rejection error server {is returned.

Listen 80

Server_name www.testpm.cn

# access_log / var/log/nginx/http_access.log main

Location / {

Root / usr/share/nginx/html; index index.html index.htm

}

Location ~ * .sh ${return 403

}

}

Example 10:80 = > 44380 to 443Port server {

Listen 80

Server_name www.testpm.cn

Access_log / var/log/nginx/http_access.log main; return 301 https://www.testpm.cn$request_uri;

}

Server {

Listen 443 ssl

Server_name www.testpm.cn

Access_log / var/log/nginx/https_access.log main

# ssl on

Ssl_certificate / etc/nginx/cert/2447549_www.testpm.cn.pem; ssl_certificate_key / etc/nginx/cert/2447549_www.testpm.cn.key; ssl_session_timeout 5m

Ssl_protocols TLSv1 TLSv1.1 TLSv1.2

Ssl_ciphers all, exp. RT56, RC4, RSAV, HIGH, Medi, LOW, ssl_prefer_server_ciphers on, SSLv2.

Location / {

Root / usr/share/nginx/html; index index.html index.htm

}

}

[root@nginx-server] # curl-I http://www.testpm.cn HTTP/1.1 301Moved Permanently

Server: nginx/1.16.0

Date: Wed, 03 Jul 2019 13:52:30 GMT

Content-Type: text/html

Content-Length: 169

Connection: keep-alive

Location: https://www.testpm.cn/

43/87

Last 、 break

[root@localhost test] # cat / etc/nginx/conf.d/last_break.conf server {

Listen 80; server_name localhost

Access_log / var/log/nginx/last.access.log main

Location / {

Root / usr/share/nginx/html; index index.html index.htm

}

Location / break/ {

Root / usr/share/nginx/html; rewrite. * / test/break.html break

}

Location / last/ {

Root / usr/share/nginx/html; rewrite. * / test/last.html last

}

Location / test/ {

Root / usr/share/nginx/html; rewrite. * / test/test.html break

}

}

[root@localhost conf.d] # cd / usr/share/nginx/html/ [root@localhost html] # mkdir test

[root@localhost html] # echo "last" > test/last.html [root@localhost html] # echo "break" > test/break.html [root@localhost html] # echo "test" > test/test.html

Http://10.0.105.196/break/break.html

Http://10.0.105.196/last/last.html

Note:

After the enforcement of this rewrite rule, the last flag will apply to the server {... } tag reinitiates the request

On the other hand, after the matching of this rule is completed, the break tag will stop the matching and will not do any subsequent matching.

When using the alias instruction, you must use last

When using the proxy_pass directive, you must use break.

44/87

Https (rewrite)

Server {

Listen 80

Server_name * .vip9999.top vip9999.top

If ($host ~ * "^ www.vip9999.top$ | ^ vip9999.top$") {return 301 https://www.vip9999.top$request_uri;

}

If ($host ~ "^ (.) .vip9999.top$") {set $user $1

Return 301 https://www.vip9999.top/$user;

}

}

Settings for a TLS enabled server.

Server {

Listen 443 ssl

Server_name www.vip9999.top

Location / {

Root / usr/share/nginx/html

} index index.php index.html

# pass the PHP scripts to FastCGI server listening on 127.0.0.1 9000 location ~ .php ${

Root / usr/share/nginx/html; fastcgi_pass 127.0.0.1 fastcgi_index index.php 9000

Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name

Include fastcgi_params

}

Ssl on

Ssl_certificate cert/214025315060640.pem; ssl_certificate_key cert/214025315060640.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m

Ssl_ciphers Higgl ssl_prefer_server_ciphers on M5

}

Localtion of nginx

The HTTP configuration of Nginx mainly consists of three blocks, with the following structure:

Http {# this is the protocol level

Include mime.types

45/87

Default_type application/octet-stream; keepalive_timeout 65

Gzip on; server {# this is at the server level

Listen 80; server_name localhost

Location / {# this is the request level root html

Index index.html index.htm

}

}

}

1. Location section

Location is configured in the server block to handle different requests according to different URI using different configurations.

The location is sequential and will be processed by the first matching location.

The basic syntax is as follows: location [= | ~ | ~ * | ^ ~ | @] pattern {. }

2. The meaning of location prefix

= indicates an exact match, and the priority is the highest

^ ~ means that uri starts with a regular string, which is understood as matching the url path. ~ represents a case-sensitive regular match ~ represents a case-insensitive regular match! ~ represents a case-insensitive regular match! ~ represents a case-insensitive regular / universal match, and any request will match to the

@ Internal service redirection

3. Location configuration example Local resolution domain name host

1) there is no modifier to indicate that you must start with the specified mode

Server {

Listen 80; server_name qf.com

Location / abc {

Root / home/www/nginx

Index 2.html

}

So, the following is true: http://qf.com/abc http://qf.com/abc?p1 http://qf.com/abc/

The following is wrong, http://qf.com/abcde

2), = means: must exactly match the specified pattern server {

Listen 80

Server_name www.testpm.cn

Access_log / var/log/nginx/http_access.log main

Location / {

Root / usr/share/nginx/html; index index.html index.htm

}

46/87

Location = / abc {

Root / usr/share/nginx/html; index index.html index.htm

}

}

So, the following is true: http://qf.com/abc http://qf.com/abc?p1 http://qf.com/abc/

Http://qf.com/abcde

3), ~ means: the specified regular expression should be case-sensitive server {

Server_name qf.com; location ~ ^ / abc$ {

……

}

}

So, the following is true: http://qf.com/abc http://qf.com/abc?p1=11&p2=22 http://qf.com/ABC http://qf.com/abc/ http://qf.com/abcde

4), ~ means: the specified regular expression is not case-sensitive server {

Server_name qf.com; location ~ ^ / abc$ {

……

}

}

So, the following is true: http://qf.com/abc http://qf..com/ABC http://qf..com/abc?p1=11&p2=22

The following is wrong: http://qf..com/abc/ http://qf..com/abcde

5), ^ ~: similar to the behavior without modifiers, it also starts with the specified pattern, except that if the pattern matches, then stop searching for other patterns. 6), @: define named location sections, which are inaccessible and can only be accessed by internally generated requests, such as try_files

Or error_page, etc.

Search order and priority 1: exact match with "=" priority 2: exact match without modifier

3: regular expressions in the order they are defined in the configuration file

4: with the "^ ~" modifier, the beginning matches

5: with the "~" or "~ *" modifier, if the regular expression matches URI

6: without modifiers, if the specified string matches the beginning of URI

= greater than ^ ~ greater than ~ ~ |! ~ |! ~ greater than /

In the case of multiple location configurations, the matching order is: first match =, then match ^ ~, then regular match, and finally hand over / universal match. When a match is successful, stop the match and process the request according to the current matching rule.

(1) =: indicates an exact match

(2) ^ ~: matches the prefix of URI, and the following regular expressions no longer match. If a URI satisfies two rules at the same time, match the longest rule.

47/87

(3) ~: match regular expressions, case-sensitive

Localtion matching segment

Example of location section matching

Location = / {

Queries that only match /. [configuration A]

}

Location / {

Matches any query that starts with /, but regular expressions and some longer strings will be matched first.

[configuration B]

}

Location ^ ~ / images/ {

Matches any query that starts with / images/ and stops the search without checking the regular expression.

[configuration C]

}

Location ~ *. (gif | jpg | jpeg) ${

Matches any file that ends with gif, jpg, or jpeg, but all requests for the / images/ directory will be processed in Configuration C. [configuration D]

}

The processing of each request is as follows:

/ → configuration A / documents/document.html → configuration B / images/1.gif → configuration C / documents/1.jpg → configuration D

Differences between root and alias instructions

Differences between root and alias instructions

Location / img/ {

Alias / var/www/image/

}

# if you follow the above configuration, ningx will automatically go to the / var/www/image/ directory to find the file location / img/ {when you access the files in the / img/ directory

Root / var/www/image

}

# if you follow this configuration, when you access the files in the / img/ directory, nginx will go to the / var/www/image/img/ directory to find the files.

Alias is a definition of a directory alias

48/87

Root is the definition of the top-level directory.

Another important difference is that alias must end with "/", otherwise the file will not be found, while root is optional.

Nginx log configuration

Introduction to nginx Log

Nginx has a very flexible logging mode, each level of configuration can have its own independent access log, the required logging module

Ngx_http_log_module is supported, and the log format is defined by the log_format command. Logs are very useful for statistics and troubleshooting. The following summarizes the configurations related to nginx logs, including access_log, log_format, open_log_file_cache, rewrite_log and error_log.

Summary:

Access log and error log are configured in Nginx through access_log and error_log instructions, and we can customize the log format through log_format. If variables are used in the log file path, we can set the cache through the open_log_file_cache directive to improve performance. Others are defined according to their own usage scenarios. For detailed log configuration information, please refer to the official Nginx documentation.

Access.log

Set the access log access_log path [format [buffer=size] [gzip [= level]] [flush=time] [if=condition]]

# disable access log access_log off

Path specifies the location where the logs are stored.

Format specifies the format of the log. Predefined combined is used by default.

Buffer is used to specify the cache size when the log is written. The default is 64k.

Gzip logs are compressed before they are written. The compression ratio can be specified, the higher the compression ratio is from 1 to 9, the slower the compression speed is. The default is 1.

Flush sets the valid time of the cache. If the time specified by flush is exceeded, the contents of the cache will be emptied.

If condition judgment. If the specified condition evaluates to 0 or an empty string, the request is not written to the log.

Scope:

The scope in which the access_log instruction can be applied is http,server,location,limit_except. That is, if you use this instruction outside of these scopes, Nginx will report an error.

Access_log / var/logs/nginx-access.log

This example specifies that the write path to the log is / var/logs/nginx-access.log, and the log format uses the default combined. Access_log / var/logs/nginx-access.log buffer=32k gzip flush=1m

49/87

This example specifies that the write path of the log is / var/logs/nginx-access.log, the log format uses the default combined, the cache size of the specified log is 32k, gzip compression is enabled before log writing, the compression ratio uses the default value of 1, and the validity time of cached data is 1 minute.

3. Log_format instruction

Nginx predefines a log format called combined, which is used by default if the log format is not explicitly specified:

Log_format combined'$remote_addr-$remote_user [$time_local]'"$request" $status $body_bytes_sent''"$http_referer"$http_user_agent"'

If you don't want to use the Nginx predefined format, you can customize it through the log_format directive. Syntax:

Log_format name [escape=default | json] string...

Name format name. Referenced in the access_log directive.

Escape sets whether the character encoding in the variable is json or default, and the default is default.

The content of the log format to be defined by string. There can be more than one parameter. The Nginx variable can be used in the parameter.

Use of custom log format: access_log / var/logs/nginx-access.log main

Log_format main'$remote_addr-$remote_user [$time_local] "$request"'$status $body_bytes_sent "$http_referer"'"$http_user_agent"$http_x_forwarded_for"'

A main format is defined using the log_format directive and referenced in the access_log directive. If the client has an initiating request: https://qf.com/, let's take a look at the log record of a request I intercepted:

10.0.105.207-[01/Jul/2019:10:44:36 + 0800] "GET / HTTP/1.1" 3040 "-" Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36 ""-"

We see that in the final logging, $remote_user, $http_referer, and $http_x_forwarded_for all correspond to one-because these variables are empty.

Error.log

The error log is implemented through the error_log instruction in Nginx. This directive records error messages during server and request processing.

Grammar

Configure the path and log level of the error log file

Error_log file [level]; Default:

Error_log logs/error.log error

The file parameter specifies where the log is written.

The level parameter specifies the level of the log. Level can be any value in debug, info, notice, warn, error, crit, alert,emerg. But

To see that the range of values is arranged from the lowest to the highest degree of urgency. Only if the error level of the log is equal to or higher than the value specified by level will be written to the error log. The default value is error.

Basic usage:

Error_log / var/logs/nginx/nginx-error.log

Configuration segment: main, http, mail, stream, server, location scope.

The example specifies that the path to the error log is: / var/logs/nginx/nginx-error.log, and the log level uses the default error.

50/87

Open_log_file_cache

Open_log_file_cache instruction

Each log record is written by opening the file and then writing the record, and then closing the log file. If you use variables such as access_log / var/logs/$host/nginx-access.log in your log file path, to improve performance, use the open_log_file_cache directive to set the cache of log file descriptors.

Syntax:

Open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time]

Default value:

Open_log_file_cache off

Max sets the maximum number of file descriptors in the cache and closes the descriptor using the LRU algorithm if it is full.

Inactive sets the cache survival time. The default is 10s.

Min_uses the log file is used at least several times during the inactive period, and the log file descriptor is cached, and the default is once.

Valid: sets how often the log file name is checked to see if it has changed. The default is 60s.

Off: no caching is used. The default is off.

Open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2; configuration segment: in the scope of http, server, location.

In the example, set the cache to cache a maximum of 1000 log file descriptors. If the log file descriptor in the cache is accessed at least twice within 20s, it will not be closed by the cache. Check whether the file name of the file descriptor in the cache still exists every 1 minute.

Rewrite.log

Rewrite_log instruction

Provided by the ngx_http_rewrite_module module. Used to record rewrite logs. It is recommended to enable debug rewrite rules. When enabled, notice-level rewrite logs will be recorded in error log.

Basic syntax: rewrite_log on | off

Default value: rewrite_log off

Configuration segment: http, server, location, if scope.

Log rotation of nginx

[root@192 ~] # rpm-ql nginx | grep log / etc/logrotate.d/nginx

51/87

/ var/log/nginx

[root@192 ~] # vim / etc/logrotate.d/nginx

/ var/log/nginx/*.log {# specifies the log files that need to be processed in rotation

Daily # Log file rotation cycle. Available values are: daily/weekly/yearly

Missingok # ignore error messages

Rotate 7 # rotation, which stores up to 7 archive logs, and deletes the longest archive log

Minsize 5m # restriction: only log files larger than 5m are divided, otherwise they will not be operated.

Dateext # takes the current date as the naming format

At the end of compress # round robin, archived logs are compressed using gzip

Delaycompress # is shared with compress. Do not compress the latest archive.

Notifempty # log file is empty and the round robin will not continue.

Create 640 nginx nginx # permissions for new log files

Sharedscripts # script is executed only once when multiple logs need to be polled

Postrotate # command executed after the log file is dumped. Ending with endscript, the command needs to be on a separate line

If [- f / var/run/nginx.pid]; then # determines the PID of nginx. # default logrotate runs kill-USR1 cat / var/run/nginx.pid as root

Fi endscript

}

Execute the command:

[root@192 nginx] # / usr/sbin/logrotate-f / etc/logrotate.conf

Create a scheduled task:

[root@192 nginx] # crontab-e

59 23 * / usr/sbin/logrotate-f / etc/logrotate.conf

Enterprise actual combat (interview)

Nginx access log analysis

A lot of valuable information can be recorded in the access log of nginx. Through the analysis of access log, many indicators can be collected. Make nginx log cutting, cut and compress in the early hours of every day.

PV:PV (visits): that is, Page View, that is, the number of page views or clicks, each time the user refreshes is counted.

UV:UV (unique visitor): Unique Visitor, the client of a computer that visits your website is a visitor. The same client is calculated only once between 00:00 and 24:00.

Interview:

1. According to visiting IP, UV awk'{print $1} 'access.log | sort | uniq-c | wc-l 2. Statistics visit URL Statistics PV

Awk'{print $7} 'access.log | wc-l 3. Query the most frequently visited URL

Awk'{print $7} 'access.log | sort | uniq-c | sort-n-k 1-r | more 4. Query the most frequently visited IP awk'{print $1} 'access.log | sort | uniq-c | sort-n-k 1-r | more 5. Query the top 10 IP visited most frequently

Awk'{print $1} 'access.log | sort | uniq-c | sort-n-k 1-r | head-n 10

Smooth upgrade of nginx (understanding)

1. Why upgrade nginx smoothly

As nginx becomes more and more popular, and the advantages of nginx become more and more obvious, the iteration of the version of nginx also comes to accelerate the mode. Version 1.9.0 of nginx has updated many new features, such as the four-tier proxy function of stream. With the wide application of nginx, the version upgrade must be faster and faster, and the online business cannot be stopped. At this time, the upgrade of nginx is the work of operation and maintenance.

52/87

Nginx conveniently helps us achieve a smooth upgrade. Its principle is simply summarized as follows: (1) start a new process without stopping the old process.

(2) the old process is responsible for processing requests that have not yet been processed, but no longer accepts requests for processing. (3) the new process accepts new requests.

(4) after the old process has processed all requests and closed all connections, it stops. This makes it easy to achieve a smooth upgrade. There are generally two situations where you need to upgrade nginx, one is to actually upgrade the version of nginx, and the other is to add a new module to nginx.

2. Nginx smooth upgrade principle request allocation method in multi-process mode

Nginx works in multi-process mode by default, that is, after the main process (master process) starts, it completes the actions such as configuration loading and port binding. Fork sends out a specified number of working processes (worker process). These child processes hold the file descriptor (fd) of the listening port and communicate with each other.

Accept the connection (accept) by adding a listening event to the descriptor. Signal reception and processing

After starting, the nginx main process will enter the waiting state and be responsible for responding to all kinds of system messages, such as SIGCHLD, SIGHUP, SIGUSR2 and so on.

Introduction to Nginx signals: signals supported by the main process

TERM, INT: quit now

QUIT: wait for the end of the work process before quitting

KILL: force termination of a process

HUP: reload the configuration file, start the worker process with the new configuration, and gradually shut down the old process.

USR1: reopen the log file

USR2: start a new main process to achieve hot upgrade

WINCH: gradually shuts down the worker process

Signals supported by the worker process

TERM, INT: quit now

QUIT: wait for the request to be processed before quitting

USR1: reopen the log file

Nginx smooth upgrade actual combat 1

1. View the existing nginx compilation parameters

[root@nginx-server] # cd / usr/local/nginx/sbin/nginx-V

2, according to the original compilation parameters to install nginx method, only need to make, do not make install. If make install overwrites the original configuration file

53/87

[root@nginx-server ~] # cd / usr/local/nginx-1.16.0/

[root@nginx-server nginx-1.16.0] # / configure-- prefix=/usr/local/nginx-- group=nginx-- user=nginx-- sbin-path=/ usr/local/nginx/sbin/nginx-- conf-path=/etc/nginx/nginx.conf-- error-log-path=/var/log/nginx/error.log-- http-log-path=/var/log/nginx/access.log-- http-client-body-temp-path=/tmp/nginx/client_body-- http-proxy -temp-path=/tmp/nginx/ proxy-http-fastcgi-temp-path=/tmp/nginx/fastcgi-- pid-path=/var/run/nginx.pid-- lock-path=/var/lock/ nginx-- with-http_stub_status_module-- with-http_ssl_module-- with-http_gzip_static_module-- with-pcre-- with-http_realip_module-- with-stream-- with-http_image_filter_module

[root@nginx-server nginx-1.16.0] # make

3. Back up the original nginx binaries, backup binaries and nginx configuration files (nginx will not stop service during this period)

[root@nginx-server nginx-1.16.0] # mv / usr/local/nginx/sbin/nginx / usr/local/nginx/sbin/nginx_$ (date +% F)

4. Copy the new nginx binary file and enter the new nginx source code package

[root@nginx-server nginx-1.16.0] # cp / usr/local/nginx-1.16.0/objs/nginx / usr/local/nginx/sbin/

5. Test whether the new version of nginx is normal.

[root@nginx-server nginx-1.16.0] # / usr/local/nginx/sbin/nginx-t

6. Send a smooth migration signal to nginx (if you don't know the pid path, please check the nginx configuration file)

[root@nginx-server] # kill-USR2 cat / var/run/nginx.pid (the old version entered the title)

7. Check nginx pid and you will see a nginx.pid.oldbin [root@nginx-server ~] # ll / var/run/nginx.pid*-rw-r--r-- 1 root root 5 Jul 1 11:29 / var/run/nginx.pid

-rw-r--r-- 1 root root 5 Jul 1 09:54 / var/run/nginx.pid.oldbin

8. Calmly shut down the old Nginx process

[root@nginx-server ~] # kill-WINCH cat / var/run/nginx.pid.oldbin

9. Do not reload the configuration to start the old worker process at this time

[root@nginx-server ~] # kill-HUP cat / var/run/nginx.pid.oldbin

10. End the work process and complete the upgrade

[root@nginx-server ~] # kill-QUIT cat / var/run/nginx.pid.oldbin

11. Verify whether the Nginx upgrade is successful

[root@nginx-server] # / usr/local/nginx/sbin/nginx-V

Nginx smooth upgrade actual combat 2

1. Install and configure nginx

[root@localhost ~] # yum install-y gcc gcc-c++ pcre-devel openssl-devel zlib-devel [root@localhost ~] # tar xzf nginx-1.6.3.tar.gz-C / usr/local/

[root@localhost ~] # cd / usr/local/nginx-1.6.3

54/87

[root@localhost nginx-1.6.3] # / configure-- prefix=/usr/local/nginx-- user=nginx-- group=nginx-- with-

Http_stub_status_module

[root@localhost nginx-1.6.3] # make & & make install

[root@localhost nginx-1.6.3] # useradd-M-s / sbin/nologin nginx

[root@localhost nginx-1.6.3] # / usr/local/nginx/sbin/nginx-t

Nginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is ok

Nginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful

[root@localhost nginx-1.6.3] # / usr/local/nginx/sbin/nginx

[root@localhost nginx-1.6.3] # netstat-lntp

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

Tcp 0 0 0.0.0 0 master 80 0.0.0 0. 0. 0 master

2. View versions and modules

[root@localhost nginx-1.6.3] # / usr/local/nginx/sbin/nginx-V nginx version: nginx/1.6.3

Built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

Configure arguments:-prefix=/usr/local/nginx-- user=nginx-- group=nginx-- with-http_stub_status_module [root@localhost nginx-1.6.3] # echo "nginx1.6" > / usr/local/nginx/html/index.html

[root@localhost nginx-1.6.3] # yum install-y elinks

3. Access verification

[root@localhost nginx-1.6.3] # elinks 10.0.105.189

4. Upgrade nginx: upgrade the nginx version and add SSL and pcre modules without affecting the business

[root@localhost ~] # tar xzf nginx-1.12.2.tar.gz-C / usr/local/ [root@localhost ~] # cd / usr/local/nginx-1.12.2/

[root@localhost nginx-1.12.2] # / configure-- prefix=/usr/local/nginx-- user=nginx-- group=ngiinx-- with-http_stub_status_module-- with-http_ssl_module-- with-pcre

[root@localhost nginx-1.12.2] # make [root@localhost nginx-1.12.2] # cd

[root@localhost ~] # mv / usr/local/nginx/sbin/nginx / usr/local/nginx/sbin/nginx_lod [root@localhost ~] # cp / usr/local/nginx-1.12.2/objs/nginx / usr/local/nginx/sbin/ [root@localhost ~] # mv / usr/local/nginx/conf/nginx.conf / usr/local/nginx/conf/nginx.conf.bak [root@localhost ~] # kill-USR2 cat / usr/local/nginx/logs/nginx.pid

[root@localhost ~] # ls / usr/local/nginx/logs/

Access.log error.log nginx.pid

[root@localhost ~] # ps aux | grep nginx

Root 13989 0.0 0.0 24860 952? Ss 13:55 0:00 nginx: master process / usr/local/nginx/sbin/nginx

Nginx 13990 0.0 0.1 25284 1720? S 13:55 0:00 nginx: worker process

Root 16525 0.0 112708 976 pts/2 S + 14:09 0:00 grep-- color=auto nginx

Nginx error interface configuration

Nginx error pages include 404, 403, 500, 502, 503, 504 and other pages. You only need to add the following configuration to server:

# error_page 404 403 500 502 503 504 / 404.html; location = / 404.html {

Root / usr/local/nginx/html

}

Note:

There must be a 404.html file under the / usr/local/nginx/html/ path!

If you reference the png or css of other files on the 404.html, there will be a problem and cannot be displayed, because the access to other files also needs to be configured. For simplicity, you can embed css in the file and embed the image with base encoding, as follows:

55/87

[root@localhost html] # vim 404.html

four hundred and four

. layout-table {display:table;height:100%;width:100%;vertical-align: middle;margin-top:150px}

.layout-table-cell {display: table-cell;vertical-align: middle;text-align:center}

.layout-tip {font-size:28px;color:#373737;margin: 0 auto;margin-top:16px;border-bottom: 1px solid # eee;padding-bottom: 20pxits width: 360px;}

# tips {font-size:18px;color:#666666;margin-top:16px;}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report