Linux Learning: nginx--reverse proxy and static and dynamic separation-04

Source: Internet
Author: User

One, the reverse proxy http

1, Nginx is usually used as the back-end server reverse proxy, so that it is easy to achieve static and dynamic separation, as well as load balancing, which greatly improve the server processing capacity.

2, Http proxy module, a lot of functions, the most commonly used is Proxy_pass

3, if you want to use Proxy_cache, you need to integrate a third-party Ngx_cache_purge module, to clear the specified URL cache, this integration needs to be done when installing Nginx,

Such as:

./confiure--add-modele=. /ngx_cache_purge-1.0 ....

Operation:

#允许客户端请求的最大的单个文件字节数

Client_max_body_size 300m;

#缓冲区代理缓冲用户端请求的最大字节数, can be understood to be saved to local and then passed to the user

Client_body_buffer_size 128k;

#跟后端服务器连接的超时时间, initiate a handshake to wait for the corresponding time-out

Proxy_connect_timeout 600;

#连接成功后, waiting for back-end server response time, in fact, has entered the back-end of the queue waiting for processing

Proxy_read_timeout 600;

#后端服务器数据回传时间, the backend server must pass all the data within the specified time

Proxy_send_timeout 600;

#代理请求缓存区, this cache interval will save the user's header information for nginx regulatory processing, generally as long as the head information can be saved

Proxy_buffer_size 16k;

Configuration nginx.conf:

Upstream xiaoliu.com {server 127.0.0.1:8080 weight=5;      } server {listen 8888;      server_name testserver1;      #access_log Logs/host.access.log Main;      Index index.html index.jsp;      root/opt/tomcat/webapps/root/;      Location/{Proxy_pass http://xiaoliu.com; }    }

Visit: http://192.168.91.6:8888/

·· 650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/8F/7E/wKioL1jh62ej1FUFAAF4MnGAGUQ909.png "title=" 111. PNG "alt=" Wkiol1jh62ej1fufaaf4mngaguq909.png "/>

Second, dynamic static separation

Nginx implementation of static and static separation, in fact, when the reverse proxy, if it is a quiescent resource, then directly from the Nginx published path to read, and do not need to get from the background server.

However, it is important to note that in this case it is necessary to ensure that the back end of the program is consistent, you can use rsync for server-side automatic synchronization or use NFS, MFS distributed shared storage.


If this tomcat works with only one and root,

Configuration nginx.conf:

upstream xiaoliu.com {    server 127.0.0.1:8080 weight=5;} Server {    listen    8888;    server_name  testserver1;     #access_log  logs/host.access.log main;     index index.html index.jsp;    root /opt/tomcat/webapps/ROOT/;          location ~* .*\. (Jpg|jpeg|gif|png|swf|ico) $ {        if  (-f  $request _ FileName)  {             #expires  15d;             break;         }    }     location ~* .*\. (html|htm|js|css) $ {        #expires  id;    }    location / {        proxy_pass http://xiaoliu.com;    }      }


If there are multiple, there is a problem with the access:

Visit: Http://192.168.91.6:8888/customermger/static/css/application.css

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/8F/7E/wKioL1jh8r6hE5o2AAANngc1MEk069.png "title=" 111. PNG "alt=" Wkiol1jh8r6he5o2aaanngc1mek069.png "/>

Visit: Http://192.168.91.6:8080/customermger/static/css/application.css

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/8F/80/wKiom1jh816wi8n1AAAaaekiM74978.png "title=" 11. PNG "alt=" Wkiom1jh816wi8n1aaaaaekim74978.png "/>

To modify the configuration nginx.conf:

upstream xiaoliu.com {    server 127.0.0.1:8080 weight=5;} Server {    listen    8888;    server_name  testserver1;     #access_log  logs/host.access.log main;     index index.html index.jsp;    root /opt/tomcat/webapps/ROOT;         location ~* ^/customermger/.*\. (Jpg|jpeg|gif|png|swf|ico) $ {        root /opt/tomcat/ Webapps;    }     location ~* ^/customermger/.*\. (HTML|HTM|JS|CSS) $ {      root /opt/tomcat/webapps;     }        location ~* .*\. (Jpg|jpeg|gif|png|swf|ico) $ {        if  (-f  $request _filename)  {             #expires  15d;            break;         }    }     location ~* .* \. (html|htm|js|css) $ {        #expires  id;    }     location / {       proxy_pass http:/ /xiaoliu.com;    }      }

This article is from "I Love Big gold" blog, please be sure to keep this source http://1754966750.blog.51cto.com/7455444/1912668

Linux Learning: nginx--reverse proxy and static and dynamic separation-04

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.