1.Nginx solve the problem of server downtime, Nginx configuration server downtime strategy, if the server goes down, it will look for the next machine to access
the configuration nginx.cfg configuration file, add the proxy address in the address mapping intercepted response plan
location / { proxy_connect_timeout 1; proxy_send_timeout 1; proxy_read_timeout 1; proxy_pass http://backserver; index index.html index.htm; }
2. cross-domain problem solving site
Nginx solve cross-domain issues, implementation:
www.a.com:8080/a
www.b.com:8081/b
cross-domain happens if a request is sent directly ajax project page in b problem, then the solution is: A and B at the same time agents to Nginx, do the Nginx request routing, direct direct access to the Nginx B project page
server { listen 80; server_name www.wdksoft.com; #charset koi8-r; #access_log logs/host.access.log main; location /a { #proxy_connect_timeout 1; #proxy_send_timeout 1; #proxy_read_timeout 1; proxy_pass http://www.a.com:8080/a/; index index.html index.htm; } location /b { #proxy_connect_timeout 1; #proxy_send_timeout 1; #proxy_read_timeout 1; proxy_pass http://www.b.com:8081/b/; index index.html index.htm; } }
B page requests:
$("#button").click(function () { $.ajax({ url:"http://www.wdksoft.com/a/AServlet?username="+$("#username").val(), type:"GET", success:function (result) { alert(result); } }) });
3.Nginx security chain configuration
using the source address Nginx be intercepted, as long as the source address matches the address of the original resource, you can access, otherwise 4.3 status codes
{Server the listen 80 ; server_name fdl.wdksoft.com; #charset KOI8 - R & lt; #access_log logs / host.access.log main; # intercept all about JPG | JPEG | JPG | PNG | GIF | icon format request LOCATION ~. . * \ (JPG | jpeg | JPG | PNG | GIF | icon) $ { # verification blocked the source address is not empty and complies address referers configuration #none allow source address is empty valid_referers blocked HTTP: // fdl.wdksoft.com / A fdl.wdksoft.com/a; # if it does not it will return 403 IF ($invalid_referer) { rewrite ^/ http://www.a.com:8080/a/img/zysx.png; #return 403; } } location /a { proxy_pass http://www.a.com:8080/a/; index index.html index.htm; } }
4.Nginx prevent DDOS attack traffic
DDOS attack traffic: frequent send requests, resulting in broadband take up, other clients can not access
Nginx solve the DDOS attack traffic, use limit_req_zone limit the number of connections to limit the number of requests limit_conn_zone
# IP limit the number of requests per second limit_req_zone Zone binary_remote_addr is $ = One: Rate = 10m lR / S; # restrictions within the same time create the same number of IP connection limit_conn_zone Zone binary_remote_addr is $ = addr: 10m; Server { the listen 80 ; server_name DDoS. wdksoft.com; LOCATION / A { limit_conn addr . 1 ; # same time can only establish a connection limit_req Zone = one; proxy_pass HTTP: // www.a.com:8080/a/; index index.html index.htm; } }