[static proxy nginx applications, static and dynamic separation]

Nginx Main applications:

 Static web server

 Load Balancing

Static Proxy
Hosting

 

Static agents

  : The access to all static resources changed access nginx, instead of accessing the tomcat, because nginx more adept at handling static resources, better performance and higher efficiency;

So in practical applications, we will be static resources such as images, css, html, js, etc. to deal with nginx instead handled by Tomcat;

Nginx static proxy how to achieve? (Can be realized by the Nginx configuration file nginx.conf)
way:
by adding location nginx.conf static resources in the configuration file, for example:
# when accessing static resources, from linux server / opt / static directory get (for example)
  LOCATION ~ * \ (JS |.. CSS | HTM | HTML | GIF | JPG | jpeg | PNG | BMP | SWF | IOC | RAR | ZIP | TXT | FLV | MID | DOC | PPT | pdf | XLS | MP3 | WMA) {$
    the root / opt / static;
  }
where:
  - a regular matching, that is to say the content of the latter may be regular expression matching;
  first point represents any character;.
  * represents one or more characters ;
  . \ is the escape character, the character is transferred back to this point;
  | representation or
  $ represents the end of
the entire configuration file to indicate the end of the suffix behind those inside the brackets by nginx process;.
placing a static directory of resources, to take note of the directory rights issue, if insufficient permissions to the directory give permission;
Second way:
  by configuring a static resource is located in the directory nginx.conf configuration file, such as:
    lOCATION ~ * / (CSS | JS | img | ImagesRF Royalty Free | Image) {.
      root / opt / static;
    }
We will static resources into / opt under / static directory, and then returns the user to access these static resources used by nginx;

 

Static and dynamic separation:

  Nginx static load balancing and proxy together, we can achieve static and dynamic separation.

  Dynamic resource, such as tomcat or jsp done by other web servers;
  static resources such as images, css, js, etc. done by nginx server;
they carry out their duties, focus on doing the things they are good at;
static and dynamic separation takes full advantage of their respective advantages, so as to achieve a more rational and efficient architecture;
static and dynamic separation exemplary

load balancing Nginx configuration:
    upstream www.p2p.com {
      Server 127.0.0.1:9100 weight =. 5;
      Server 127.0.0.1:9200 weight = 2;
    }

  upstream static.p2p {.com
    Server 127.0.0.1:81 weight =. 1;
    Server = weight 127.0.0.1:82. 1;
  }
  LOCATION / P2P {
    proxy_pass http://www.p2p.com;
  }

  . ~ LOCATION * / (CSS | JS | IMG | Images) {
    proxy_pass http://static.p2p.com;
  }
static proxy Nginx configuration:
  LOCATION ~ * / (CSS | JS | IMG | Images) {.
    the root / opt / static;
  }

Guess you like

Origin www.cnblogs.com/yhm9/p/11183472.html