Nginx在Windows环境中的服务搭建

1、在磁盘新建两个目录 tomcat1 tomcat2
2、修改tomcat2的端口
3、代理单个服务器方式:修改 conf 目录下的 nginx.conf 文件

代码如下:

location / {
	root   html;
	index  index.html index.htm;
	proxy_pass http://localhost:8080;
}

4、代理集群(即代理多个服务器):修改 conf 目录下的 nginx.conf 文件

代码如下:

#gzip  on;

upstream server_xxx{
	#通过 weight 属性可设置被代理服务器权重,值越大权重越高,越容易被访问(可省略)
	server 127.0.0.1:8080 weight=1;
	server 127.0.0.1:8081 weight=2;
}

server {
	listen       80;
	server_name  localhost;
	
	#charset koi8-r;
	
	#access_log  logs/host.access.log  main;
	
	location / {
	root   html;
	index  index.html index.htm;
	#代理单个服务器
	#proxy_pass http://localhost:8080;
	#代理集群
	proxy_pass http://server_xxx;
}

#error_page  404              /404.html;

5、session共享问题

解决方式1:只能在 windows 下使用

web服务器解决(广播机制:tomcat下性能低

解决方式1:

  • 修改 tomcatserver.xml 支持共享即将server.xml中的 <Engine name="Catalina" defaultHost="localhost"> 标签下的<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> 注释去掉。

  • 修改项目的配置文件即在 web.xml 中添加一个节点:<distributable/>

解决方式2:

  • 可以将 sessionid 放入 redis

解决方式3:

  • 保证一个ip地址永远的访问一台web服务器,就不存在session共享问题了,在linux因此在nginx的配置文件中 upstream 中添加 ip_hash;

PS: 内容整理自网络

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值