下文给大家带来nginx反向代理工程加入负载均衡及动静分离配置详解,希望能够给大家在实际运用中带来一定的帮助,负载均衡涉及的东西比较多,理论也不多,网上有很多书籍,今天我们就用在行业内累计的经验来做一个解答。
nginx反向代理多个工程,加入了负载均衡及动静分离的配置
#用户,没有人;
worker_processes, 4,
error_log,日志/错误。日志,信息;
pid,,,,日志/nginx.pid;
worker_rlimit_nofile 65535;
事件{
,,worker_connections, 65535;
}
http {
,,包括,,,mime.types;
,,default_type,应用程序/八进制;
,,log_format,主要,& # 39;remote_addr - remote_user美元($ time_local]“request"美元;& # 39;
,,,,,,,,,,,& # 39;地位body_bytes_sent美元“http_referer"美元;& # 39;
,,,,,,,,,,,& # 39;“http_user_agent"美元;“美元http_x_forwarded_for" & # 39;;
server_names_hash_bucket_size 128;,
,,client_header_buffer_size 32 k;,
,,large_client_header_buffers 4 32 k;,
,,client_max_body_size 300;,
,,上游bsxm {sendfile>
,,,,ip_hash;
,,,,服务器192.168.1.193:8080;
,,,,}
,,#指定静态页面路径
服务器{
,,,,听,,,80;
,,,,server_name, 192.168.1.193;
,,,,,,,,根,C: \ webapps \ bsxmgw \页;
,,,,,,,,指数指数。html你;
#加载静态文件,因为在下面的反向代理中已配置,这里根据需求选用
# ~ ^/位置(p_w_picpaths | | js javascript css flash媒体| | | |静态)/,{
,,,,,#根,,,,C: \ webapps \ bsxmgw;
,,,,# access_log;
,,,,,号到期,,30 d;
,,#}
, #反向代理配置
位置/{
,,,, proxy_set_header X-Real-IP remote_addr美元;,
,,,, proxy_set_header远程主机remote_addr美元;,
,,,, proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for美元;
,,,,,,,, #纯反向代理配置
,,,, #位置/webapps/
,,,, # {
,,,,,,,, # proxy_pass http://192.168.1.193:8080;
,,,, #}
,,,,,,,,#负载均衡
,,,, ~ \位置。(jsp |行动)$
,,,, {
,,,,proxy_pass http://bsxm;
,,,,# client_max_body_size 1000;,,,,,,,
,,,}
,,,, ~ \位置。(gif | jpg | jpeg | png | bmp | swf | flv) $
,,,{
,,,,到期,,,30 d; #所有静态文件缓存30天
,,,}
,,~ \位置。(js | css) ? $
,,{
,,,,到期,,,1 h;
,,,}
}
#反向代理工程,
位置/b/{
,,,,,,,,proxy_pass http://192.168.1.193:8080/b/;
#根,C: \ webapps \ b;当使用纯反向无法访问工程时可以这几个配置开启
# proxy_redirect,主持人:美元http://host: 8080 http://server_port;
#指数指数。html你;
,,,,,,,,}
,,,,,,,,
#反向代理工程
位置/a/{
,,,,,,,,proxy_pass http://192.168.1.193:8080/;
#根,C: \ webapps \;
# proxy_redirect,主持人:美元http://host: 8080 http://server_port;
#指数指数。html你;
,,,,,,,,}
#访问地址;为http://localhost/a , http://localhost/b
,,,,# error_page, 404,,,,,,,404./html;
,,,,#服务器错误页面重定向到静态页面/50 x.html
,,,,#
,,,,error_page,500 502 503 504,/50 x.html;
,,,,位置=/50 x。html {
,,,,,,根,null null