Using Nginx error_page to make redundant 404 files
SOURCE by: Multiple picture server picture has a difference, may appear to visit a server appears 404, now need to be accessible regardless of access.
Train of thought: plan to use the following three methods, because the time is too short method 1 should be feasible but no time, Method 2 simple test did not pass, method 30% the only choice to check the multi-data to fix, found online a lot of information is not complete, according to the configuration should not appear the expected results, now summarized as follows.
Follow-up: Follow-up look at the effect, do not know if there is a bug, resulting in a dead loop.
1,lua Script
2,proxy_next_upstream
3,error_page
Subject:
I. References
Proxy_intercept_errors
Http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_proxy_module.html
when the back-end server's response status code is greater than or equal to 400, it decides whether to send the response directly to the client, or to send the response to Nginx handled by the error_page instruction.
Upstream
Http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_upstream_module.html
Max_fails=number
Sets the number of failed attempts by nginx to communicate with the server. In the time period defined by the Fail_timeout parameter, if the number of failures reaches this value, Nginx considers the server unavailable. In the next fail_timeout time period, the server will no longer be tried. The default number of failed attempts is 1. Set to 0 will stop the count of attempts, the server is considered to be available. You can configure what is a failed attempt by means of directives proxy_next_upstream, Fastcgi_next_upstream, and Memcached_next_upstream. The http_404 state is not considered a failed attempt when the default configuration.
Fail_timeout=time
Sets the time period for the count of failed attempts. During this time, the number of server failures reached the specified number of attempts and the server was considered unavailable. The time period that the server is considered unavailable. By default, the time-out is 10 seconds.
Error_page
Http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_core_module.html#error_page
If you do not need to change the URI when jumping internally, you can move the error handling to a named path:
Location/{Error_page 404 = @fallback;} Location @fallback {Proxy_pass http://backend;}
If the processing URI produces an error, then Nginx returns the last error HTTP response status code to the client, which means the server's response code will be displayed directly if the standby server is not working.
Second, the relevant configuration:
server { listen 80; server_name test.com; index index.html index.htm; location / { proxy_pass http://online; error_page 404 = @fallback; proxy_intercept_errors on; } location @fallback { proxy_pass http://backend; }}upstream online { server 192.168.88.18:80; server 192.168.88.28:80;} Upstream backend { server 192.168.88.38:80 ;}
Third, test:
Test1.html on the first server, test2.html on the second server, test3.html nowhere
192.168.88.188--[09/nov/2016:17:07:13 +0800] "get/test1.html http/1.1"-"curl/7.15.5 (x86_64-redhat-linux-gn u) libcurl/7.15.5 openssl/0.9.8b zlib/1.2.3 libidn/0.6.5 " -192.168.88.188--[09/nov/2016:17:07:15 +0800]" get/test2.ht ML http/1.1 "$"-"curl/7.15.5 (X86_64-REDHAT-LINUX-GNU) libcurl/7.15.5 openssl/0.9.8b zlib/1.2.3 libidn/0.6.5"-19 2.168.88.188--[09/nov/2016:17:27:47 +0800] "get/test3.html http/1.1" 404 583 "-" "curl/7.15.5 (X86_64-redhat-linux-gnu ) libcurl/7.15.5 openssl/0.9.8b zlib/1.2.3 libidn/0.6.5 "-
Redundancy of 404 files using Nginx error_page