Nignx 做代理服务器01

本文详细介绍了如何在Sentos操作系统上部署两个Tomcat服务器,并通过Nginx实现负载均衡,使得本地访问www.eshop.tomcat.com时能够自动在两个Tomcat实例之间切换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在Sentos上运行两个tomcat;

方法,修改server.xml文件的端口号。

在Nginx的配置文件中添加一个Server:

#user  nobody;
worker_processes  1;

#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 {
    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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  www.test.nginx.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }



#lanqie change
#make 1 domain for application

	server {
		listen       80;
		server_name  www.eshop.com;

		#charset koi8-r;

		#access_log  logs/host.access.log  main;

		location / {
		    root   html2;
		    index  index2.html index2.htm;
		}

	}

#@lanqie 
#make 2 tomcat for application


upstream tomcats{

	server 192.168.10.128:8080;
	server 192.168.10.128:8081;

}

server {
		listen       80;
		server_name  www.eshop.tomcat.com;

		#charset koi8-r;

		#access_log  logs/host.access.log  main;

		location / {
		    
		    proxy_pass   http://tomcats;
		    index  index2.html index2.htm;
		}

	}



}

以上为虚拟机环境。

当本地访问

 www.eshop.tomcat.com
时Nginx会自动在2个tomcat中切换

当然,前提要在hosts文件中解析域名:

# Copyright (c) 1993-2009 Microsoft Corp.


192.168.10.128      www.test.nginx.com
192.168.10.128      www.eshop.com
192.168.10.128      www.eshop.tomcat.com



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值