: This article mainly introduces nginx Reverse proxy tomcat to achieve load balancing. if you are interested in the PHP Tutorial, please refer to it.
In a computer network, reverse proxy is a type of proxy server. It obtains resources from the backend server based on client requests and then returns these resources to the client. Unlike the forward proxy, the forward proxy acts as a media to return resources obtained on the Internet to the associated client, while the reverse proxy acts as a proxy on the server, not the client.
Nginx (pronounced the same as engine x) is a web server that can reverse proxy HTTP, HTTPS, SMTP, POP3, IMAP protocol links, as well as a load balancer and an HTTP cache.
It was initially used by a large Russian Portal website and search engine Rambler (Russian: Russian simplified. This software is released under the BSD-like protocol and can be run on UNIX, GNU/Linux, BSD, Mac OS X, Solaris, Microsoft Windows, and other operating systems.
: Http://nginx.org/en/download.html
After the download is complete, decompress it to any directory and double-click nginx.exe to start
The localhost is successfully started.
Open the main configuration file conf/nginx. conf of nginx.
server { listen 80; server_name localhost; #charset koi8-r;#access_log logs/host.access.log main; location / { root html; indexindex.html index.htm; } #error_page 404 /404.html;# redirect server error pages to the static page /50x.html# error_page 500502503504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#} }
Listen: The Port listened by the current proxy server. the default port is port 80. Note: If multiple servers are configured, the listen configuration must be different. Otherwise, you cannot determine where to go.
Server_name: indicates where to go after listening. in this case, we directly go to the local directory and then directly go to the nginx folder.
Location: indicates the matched path. if/is configured, all requests are matched here.
Root: if the root file is configured in it, it indicates that when the request path is matched, the corresponding files will be searched in this folder, which is useful for our static file servo.
Index: if no home page is specified, the specified file is selected by default. it can have multiple files and load them in order. if the first file does not exist, find the second one, and so on.
The following error_page indicates an error page. We do not need it for the time being.
Forwarding to tomcat requires modification in two places
server_name localhost:8080; location / { proxy_pass http://localhost:8080; }
We modified the above two places. my tomcat is on port 8080 and can be modified as needed. There is a new element proxy_pass, which indicates the proxy path, which is equivalent to forwarding, rather than specifying a folder as the root mentioned earlier.
Now we have modified the file, doesn't it mean we have to shut down nginx and restart it? in fact, we don't have to. nginx can reload the file.
Nginx-s reload
Besides other commands, nginx must be run under the command line.
Open localhost and proxy to tomcat
Server load balancer configuration
Upstream local_tomcat {server localhost: 8080; server localhost: 9080;} server {listen 80; server_name localhost; # directly matches the website root, and the website homepage is frequently accessed through the domain name, this will accelerate processing, as said on the official website. # This is directly forwarded to the backend application server, or a static homepage # The first required rule location =/{proxy_pass http: // local_tomcat/index} # The second mandatory rule is to process static file requests. this is the strength of nginx as an http server # There are two configuration modes, directory matching or suffix matching, choose either of them or use location ^ ~ /Static/{root/webroot/static/; expires 24 h;} location ~ *\. (Gif | jpg | jpeg | png | css | js | ico) $ {root/webroot/res/; expires 30d ;}# The third rule is a general rule, used to forward dynamic requests to the backend application server # Non-static file requests are dynamic requests by default. you can grasp them based on your own needs. # After all, some frameworks are currently popular. php ,. jsp suffixes are rare. location/{proxy_pass http: // local_tomcat }}
Disable nginx: nginx-s stop
Reference: http://nginx.org/en/docs/windows.html
Http://cxshun.iteye.com/blog/1535188
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces nginx Reverse proxy tomcat to achieve load balancing, including content, hope to be helpful to friends interested in PHP tutorials.