nginx common interview questions 1

Nginx is a corner that web server operation and maintenance personnel cannot avoid. The remaining high-risk interview areas are: Linux basics, network knowledge basics, python, and perhaps monitoring tools such as zabbix. Let's talk about nginx first, and the following ones will definitely be written.

 

test questions

[Question 1] In the nginx + php-fpm environment installed by default, if the user browses a time-consuming web page, but closes the browser in the middle of rendering the page on the server side, then ask whether the php script on the server side will continue to execute or exit the execution. ?

[Answer] Under normal circumstances, if the client client exits abnormally, the server program will continue to execute until two interactive operations with IO are performed. The server finds that the client has been disconnected. At this time, a user_abort will be triggered. If this ignore_user_abort is not set, the php-fpm program will be interrupted.

Further reading: http://www.cnblogs.com/yjf512/p/5362025.html?foxhandler=RssReadRenderProcessHandler

 

[Question 2] First of all, what time does $time_local in the Nginx log format represent? When did the request start? When does the request end? Secondly, when we observe the $time_local time in the log from front to back, sometimes we find that the time sequence is out of order, please explain the reason.

[Answer] $time_local: The time when the request starts to be written to the local server in the server. Because the request occurs before and after, the time sequence will be disordered.

 

[Question 3] In the Nginx+PHP environment, the following error message occasionally appears in the Web error log: "recv() failed (104: Connection reset by peer) while reading response header from upstream", please analyze the possible reasons .

[Answer] In this case, the first solution is to restart the php service, service php5-fpm restart, but this cures the symptoms but not the root cause. The solution is to change the pm.max_requests value of php to a larger value, such as 500; The second method is to modify the request_terminate_timeout of php-fpm and change the value to =0.

 

This situation depends on the back-end php, either the link fails, or the php service hangs, or the link times out.

If the number of workers is not enough, it will be 504, and the worker processing timeout will be 502.

Further reading: http://serverfault.com/questions/543999/nginx-errors-recv-failed-104-connection-reset-by-peer-while-reading-respon

 

[Question 4] It is known that Nginx and PHP-FPM are installed on the same server. There are two ways for Nginx to connect to PHP-FPM: one is a TCP socket similar to 127.0.0.1:9000; the other is similar to /tmp/php - Unix domain socket for fpm.sock. How to choose and what to pay attention to.

[Answer] The process of the Unix domain socket will not go to the TCP layer, but communicate directly with the stream socket in the form of a file. If it is a TCP socket, you need to go to the IP layer. To put it simply, the pursuit of reliability is tcp (it needs to occupy a port, which is more stable), and the pursuit of high performance is Unix Socket (does not need to occupy a port, it is faster).

Further reading: https://blog.linuxeye.com/364.html

http://www.cnxct.com/default-configuration-and-performance-of-nginx-phpfpm-and-tcp-socket-or-unix-domain-socket/  (This article is highly recommended, very well written! )

 

[Question 5] In Nginx, please explain the difference between break and last in the Rewrite module.

[Answer] The definition of the official document is as follows:

last: stop executing the current round of the ngx_http_rewrite_module instruction set, and then find a new location that matches the changed URI;
break: stop executing the current round of the ngx_http_rewrite_module instruction set;

A thousand words for an example:

location /test1.txt/ {

        rewrite /test1.txt/ /test2.txt break;

}

        location ~ test2.txt {
        return 508;
}


Using break will match the URL twice, if there is no match, it will stop matching the following location , directly initiate a request to www.xxx.com/test2.txt, since there is no file test2.txt, 404 will be displayed directly.
If last is used, it will continue to search for the following locations that meet the conditions (matching the rewritten /test2.txt request), and match ten times. If no results are obtained ten times, then it is the same as break. Returning to the above example, /test2.txt just corresponds to the condition of the surface location. Enter the code in the curly braces {} to execute, and 508 will be returned here. (508 here is set by me casually)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324894242&siteId=291194637