博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx负载均衡配置
阅读量:7067 次
发布时间:2019-06-28

本文共 2533 字,大约阅读时间需要 8 分钟。

hot3.png

`文件目录结构

这里主要介绍配置文件目录conf

目录:/usr/local/nginx/conf

包含配置文件:nginx.conf

backends/demo.cn.conf          sites/demo.cn.conf

具体文件配置如下:

nginx.conf:

#user nobody;

worker_processes 1;

#nginx异常日志

error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

events {

worker_connections  1024;

}

http {

fastcgi_intercept_errors on;     include       mime.types;    default_type  application/octet-stream;    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                  '$status $body_bytes_sent "$http_referer" '                  '"$http_user_agent" "$http_x_forwarded_for""::::" "$Host"';

#nginx接收请求的日志

access_log  logs/access.log  main;    sendfile        on;    #tcp_nopush     on;#keepalive_timeout  0;

keepalive_timeout 65;

include mime.types;

default_type application/octet-stream;

charset utf-8 ;server_names_hash_bucket_size 128;client_header_buffer_size 2k;large_client_header_buffers 4 4k;client_max_body_size 8m;

sendfile on;

tcp_nopush on;keepalive_timeout 600s;#fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2#keys_zone=TEST:10m#inactive=5m;fastcgi_connect_timeout 600s;fastcgi_send_timeout 600s;fastcgi_read_timeout 600s;fastcgi_buffer_size 10m;fastcgi_buffers 8 10m;fastcgi_busy_buffers_size 10m;fastcgi_temp_file_write_size 10m;

fastcgi_cache TEST;

fastcgi_cache_valid 200 302 1h;fastcgi_cache_valid 301 1d;fastcgi_cache_valid any 1m;fastcgi_cache_min_uses 1;fastcgi_cache_use_stale error timeout invalid_header http_500;open_file_cache max=204800 inactive=20s;open_file_cache_min_uses 1;open_file_cache_valid 30s;tcp_nodelay on;gzip on;gzip_min_length 1k;gzip_buffers 4 16k;gzip_http_version 1.0;gzip_comp_level 2;#gzip_types text/plain application/x-javascript text/css application/xml;gzip_vary on;#gzip  on;

#负载分发具体配置文件

include backends/*; 数据转发配置

include sites/*;

}

数据转发配置文件

backends/demo.cn.conf

#mvc为tomcat下系统工程名字

upstream mvc{

server 192.168.3.51:8088; 部署系统的两台服务器之一(tomcat)

server 192.168.3.51:8089; 部署系统的两台服务器之一(tomcat)

}

正文处理配置文件

sites/demo.cn.conf

server{

listen 80;  监听端口  server_name demo.cn;  请求主域名  location ~ /mvc/(.*){  请求路径中带有   /mvc/的处理       proxy_pass http://mvc;      proxy_redirect off;       proxy_set_header Host $host;   proxy_set_header X-Real-IP $remote_addr;   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  }

}

本次demo的应用名称为mvc,通过nginx进行访问的路径为 demo.cn/mvc/

在局域网访问时 需要配置host 127.0.0.1 demo.cn

至此,demo全部配置完成,扩展使用nginx的其他功能需阅读nginx官方文档```

这里输入代码

 

转载于:https://my.oschina.net/selfdesign/blog/883485

你可能感兴趣的文章
Python笔记001-类的特殊方法
查看>>
10分钟快速精通rollup.js——Vue.js源码打包原理深度分析
查看>>
在 create-react-app 中启用装饰器语法
查看>>
python中的数据类型(list,tuple,dict,set,None)
查看>>
通过 Snabbdom 理解 Virtual DOM
查看>>
原生JS实现类似《掘金》网站的图片查看器
查看>>
微服务架构下,解决数据一致性问题的实践
查看>>
2019,Web前端开发还值得学吗?
查看>>
理财基金篇二——基金理财的种类
查看>>
我的友情链接
查看>>
HTML(超文本标记语言)之【动态网页】
查看>>
【Linux】修改"$PATH"环境变量的探索
查看>>
我的友情链接
查看>>
firefox各版本下载地址
查看>>
Dubbo之ProxyFactory
查看>>
Spring之getBean
查看>>
远程访问服务 (RAS) 错误代码列表
查看>>
java.util.concurrent.atomic与CAS详解
查看>>
天猫魔盒 华数盒子双清
查看>>
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 的说明
查看>>