Nginx reverse proxy, load balancing and static and dynamic separation

Source: Internet
Author: User

1. Environment:

Front-end Nginx Server: Host Name: node5.a.com

ip:192.168.10.205 compiling and installing Nginx 1.6.3

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/95/wKioL1VM1zLTNQG6AACdSR7YkGY407.jpg "title=" 1.jpg " alt= "Wkiol1vm1zltnqg6aacdsr7ykgy407.jpg"/>

Back-end Tomcat:

server1--ip:192.168.10.209 Host Name: node9.a.com

SERVER2--IP:192.168.10.210 Host Name: node10.a.com

2, Ngginx configuration:

User Nginx;

Worker_processes 1;

Events {

Use Epoll;

Worker_connections 4096;

}

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Sendfile on;

Tcp_nopush on;

Tcp_nodelay on;

Server_tokens off;

Keepalive_timeout 65;

Server_names_hash_max_size 1024;

gzip on;

Gzip_proxied any;

Gzip_min_length 1000;

Gzip_comp_level 4;

Gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml Application/xml+rss Text/javascript;

Gzip_static on;


Upstream Tomcat {#定义一个tomcat服务器集群, which is the IP and port of the included server;

Server 192.168.10.209:8080;

Server 192.168.10.210:8080;

}

server {

Listen 80; #定义一个监听的端口

server_name node5.a.com; #定义虚拟主机的名称

Location/{

Root html/www; #虚拟主机的默认根目录

Index index.jsp index.html index.htm; #识别的首页文件类型

}

Location ~* \. (Jsp|do) $ {#不区分带小写正则匹配, counter request. JSP and DP end requests are evenly distributed to the back-end server cluster tomcat.

Proxy_pass Http://tomcat; #将匹配请求转发至tomcat集群

}

Location ~* \. (jpg|png|gif|jgeg|pdf) $ {#不区分大小写匹配括号内定义的文件类型

Proxy_pass http://192.168.10.209:8080; #转发至该服务器

}

}

Include html/*.conf; #读取该目录里面的. conf file

}

3, verify:

1) Visit node5.a.com:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6C/99/wKiom1VM18rS3P_XAAChLmBLl0M836.jpg "title=" 1.jpg " alt= "Wkiom1vm18rs3p_xaachlmbll0m836.jpg"/>

2) Visit node5.a.com/index.jsp

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/95/wKioL1VM2g7Bna42AAHCRhPio4g416.jpg "title=" 1.jpg " alt= "Wkiol1vm2g7bna42aahcrhpio4g416.jpg"/>

Refresh yourself:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6C/95/wKioL1VM2YvgeW1bAACZobm67ZQ075.jpg "title=" 1.jpg " alt= "Wkiol1vm2yvgew1baaczobm67zq075.jpg"/>

Note: Due to the explicit definition in the Nginx configuration file where exact match is made. The request at the end of the JSP is forwarded to the Tomcat cluster, so the request will not be completed in Nginx native, but will be forwarded to the server cluster. In addition, because two servers are defined in the cluster, user requests are assigned in turn, which is the ability to load balance:

3) Visit node5.a.com/1.jpg

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/99/wKiom1VM2QyBnqhMAAOS94DHC_Y377.jpg "title=" 1.jpg " alt= "wkiom1vm2qybnqhmaaos94dhc_y377.jpg"/> Note: define ~* \ in Nginx.cong. (jpg|png|gif|jgeg|pdf) $ i.e. all requests ending with jpg|png|gif|jgeg|pdf are forwarded to the 192.168.10.209 server for processing, so 1.jpg files need to be placed under 192.168.10.209/opt /root/1.jpg.

This article is from the "Linux" blog, so be sure to keep this source http://zhangshijie.blog.51cto.com/806066/1649757

Nginx reverse proxy, load balancing and static and dynamic separation

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.