Configuring Nginx's reverse proxy and load balancing

Source: Internet
Author: User

In a word, the address of the Nginx server is actually requested, but the user actually sees the corresponding page of tomcat that we configured, this is the Nginx reverse proxy. Our nginx is the proxy server, and he will distribute our request to the actual server.

Configuring the reverse proxy in the nginx.conf file

In the Nginx directory, enter the command CD conf/

Input Vim ngnix.conf

Configure the following red font to save

Upstreamtomcat_server {

Server 192.168.25.143:8080; Specify the Tomcat_server

}

server {

Listen 80;

server_name localhost;

#charset Koi8-r;

#access_log Logs/host.access.log Main;

Location/{

Proxy_pass Http://tomcat_server; Configure the server that you are acting on

root HTML;

Index index.html index.htm;

}

Test the configuration is successful, start Nginx, directly in the browser to access the address of the Nginx server, if you jump to the configured Tomcat server, the configuration is successful.


Load-balanced configuration, very simple, just need to

Upstreamtomcat_server {

Server 192.168.25.143:8080; Specify the Tomcat_server

Add a Tomcat server address, as follows

Upstream Tomcat_server {

Server 192.168.25.143:8080 weight=20;

Server 192.168.25.144:8080 weight=20; Weight is a weight, and two values are equal to the probability of being distributed by Nginx.

}

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.