Nginx+tomcat load Balancing + static and dynamic separation

Source: Internet
Author: User
Tags epoll sendfile

1, Server A installation Ng, Server B, c installation tomcat;

2, Server A set up/data/www directory for the release of static files;

3, ng no static separation configuration;

User root root;worker_processes 8;pid/usr/local/nginx/nginx.pid;worker_rlimit_nofile 102400;events{use epoll;worker _connections 102400;}  http{include mime.types;  Default_type Application/octet-stream;  Fastcgi_intercept_errors on;  CharSet Utf-8;  Server_names_hash_bucket_size 128;  Client_header_buffer_size 4k;  Large_client_header_buffers 4 32k;  Client_max_body_size 300m;  Sendfile on;     Tcp_nopush on;     Keepalive_timeout 60;  Tcp_nodelay on;   Client_body_buffer_size 512k;  Proxy_connect_timeout 5;  Proxy_read_timeout 60;  Proxy_send_timeout 5;  Proxy_buffer_size 16k;  Proxy_buffers 4 64k;  Proxy_busy_buffers_size 128k;     Proxy_temp_file_write_size 128k;  gzip on;  Gzip_min_length 1k;  Gzip_buffers 4 16k;  Gzip_http_version 1.1;  Gzip_comp_level 2;  Gzip_types text/plain application/x-javascript text/css application/xml;   Gzip_vary on; # # #2012 -12-19 change nginx logslog_format main ' $http _x_forwarded_for-$remotE_user [$time _local] "$request" "$status $body _bytes_sent" $http _referer "" "$http _user_agent               "$request _time $remote _addr '; Upstream Web_app {server 192.168.203.130:10086 weight=1 max_fails=2 fail_timeout=30s; server 192.168.203.131:10087 Weight=1 max_fails=2 fail_timeout=30s;}    # # # #chinaapp. sinaapp.comserver {Listen 80;    server_name chinaapp.sinaapp.com;    Index index.jsp index.html index.htm;         # published directory:/data/www root/data/www;        Location/{proxy_next_upstream http_502 http_504 error timeout invalid_header;        Proxy_set_header Host $host;        Proxy_set_header X-real-ip $remote _addr;        Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;        Proxy_pass Http://web_app;    Expires 3d; }    } }
View Code

4, Ng static and dynamic separation configuration;

User root root;worker_processes 8;pid/usr/local/nginx/nginx.pid;worker_rlimit_nofile 102400;events{use epoll;worker _connections 102400;}  http{include mime.types;  Default_type Application/octet-stream;  Fastcgi_intercept_errors on;  CharSet Utf-8;  Server_names_hash_bucket_size 128;  Client_header_buffer_size 4k;  Large_client_header_buffers 4 32k;  Client_max_body_size 300m;  Sendfile on;     Tcp_nopush on;     Keepalive_timeout 60;  Tcp_nodelay on;   Client_body_buffer_size 512k;  Proxy_connect_timeout 5;  Proxy_read_timeout 60;  Proxy_send_timeout 5;  Proxy_buffer_size 16k;  Proxy_buffers 4 64k;  Proxy_busy_buffers_size 128k;     Proxy_temp_file_write_size 128k;  gzip on;  Gzip_min_length 1k;  Gzip_buffers 4 16k;  Gzip_http_version 1.1;  Gzip_comp_level 2;  Gzip_types text/plain application/x-javascript text/css application/xml;   Gzip_vary on; # # #2012 -12-19 change nginx logslog_format main ' $http _x_forwarded_for-$remotE_user [$time _local] "$request" "$status $body _bytes_sent" $http _referer "" "$http _user_agent               "$request _time $remote _addr '; Upstream Web_app {server 192.168.203.130:10086 weight=1 max_fails=2 fail_timeout=30s; server 192.168.203.131:10087 Weight=1 max_fails=2 fail_timeout=30s;}    # # # #chinaapp. sinaapp.comserver {Listen 80;    server_name chinaapp.sinaapp.com;    Index index.jsp index.html index.htm;         # published directory:/data/www root/data/www;        Location/{proxy_next_upstream http_502 http_504 error timeout invalid_header;        Proxy_set_header Host $host;        Proxy_set_header X-real-ip $remote _addr;        Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;        Proxy_pass Http://web_app;    Expires 3d; } location ~. *\.         (HTML|HTM|GIF|JPG|JPEG|BMP|PNG|ICO|TXT|JS|CSS) $ {root/data/www;         #expires定义用户浏览器缓存的时间为3天, if the static page is not updated frequently, can be set longer, which can save bandwidth and relieve the pressure of the server expires 3d; }    } } 
View Code

5, install NG without specifying the compilation parameters, direct./configure--prefix=/usr/local/nginx & make & make install on the line;

6, the direct access to the domain name here will still request Tomcat, do not understand why, only the domain name with a specific static files will be requested from NG;

Nginx+tomcat load Balancing + 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.