Nginx反向代理,反向代理nginx网站,tomcat网站

配置环境准备

节点IP地址角色
nginx192.168.44.173反向代理服务器
web1192.168.44.174网站1(nginx网站)
web2192.168.44.175网站2(nginx网站)
web3192.168.44.176网站3(tomcat网站)

网站安装部署

web1部署

使用nginx部署网站,安装nginx

#进入nginx解压目录
[root@web1 nginx]#	yum -y install make gcc psmisc  pcre-devel openssl openssl-devel
#部署加密网站需要--with-http_ssl_module模块,本次虽含有此模块但未使用
[root@web1 nginx]#	./configure --with-http_ssl_module
[root@web1 nginx]#	make && make install

修改配置文件,指定网页位置

#进入nginx安装目录
[root@web1 nginx]#	cd /usr/local/nginx/
#修改配置文件,指定网页位置
[root@web1 nginx]#	vim conf/nginx.conf
#x新增一个location
location /web1 {
             alias /data/nginx;
             try_files $uri /web1/index.html;
        }

部署网页

#部署网页
[root@web1 nginx]#	mkdir -p /data/nginx
[root@web1 nginx]#	echo web1_test~~~ > /data/nginx/index.html

启动服务

#启动服务
[root@web1 nginx]#	sbin/nginx
[root@web1 nginx]#	ss -utnlp | grep nginx
tcp    LISTEN     0      128       *:80                    *:*                   users:(("nginx",pid=16369,fd=6),("nginx",pid=3945,fd=6))

本机测试访问

#本机测试访问
[root@web1 nginx]#	curl http://192.168.44.174/web1/
web1_test~~~

web2部署

使用nginx部署网站,安装nginx

#进入nginx解压目录
[root@web2 nginx]#	yum -y install make gcc psmisc  pcre-devel openssl openssl-devel
#部署加密网站需要--with-http_ssl_module模块,本次虽含有此模块但未使用
[root@web2 nginx]#	./configure --with-http_ssl_module
[root@web2 nginx]#	make && make install

修改配置文件,指定网页位置

#进入nginx安装目录
[root@web2 nginx]#	cd /usr/local/nginx/
#修改配置文件,指定网页位置
vim conf/nginx.conf
#x新增一个location
location /web2 {
             alias /data/nginx;
             try_files $uri /web2/index.html;
        }

部署网页

#部署网页
[root@web2 nginx]#	mkdir -p /data/nginx
[root@web2 nginx]#	echo web2_test~~~ > /data/nginx/index.html

启动服务

#启动服务
[root@web2 nginx]#	sbin/nginx
[root@web2 nginx]#	ss -utnlp | grep nginx
tcp    LISTEN     0      128       *:80                    *:*                   users:(("nginx",pid=16412,fd=6),("nginx",pid=3944,fd=6))

本机测试访问

#本机测试访问
[root@web2 nginx]#	curl 192.168.44.175/web2/
web2_test~~~

web3部署

使用tomcat部署网站,安装tomcat

#安装tomcat
#解压tomcat,把解压后的目录放到/usr/local/tomcat
[root@web3 ~]#	tar xf apache-tomcat-9.0.6.tar.gz
[root@web3 ~]#	cp -r apache-tomcat-9.0.6 /usr/local/tomcat
#安装tomcat运行以来java环境
[root@web3 ~]#	yum -y install java-1.8.0-openjdk
#配置tomcat运行依赖大量随机字符
[root@web3 ~]#	 mv /dev/random /dev/random.bak
[root@web3 ~]#	 ln -s /dev/urandom /dev/random

修改配置文件,指定网页位置

bin  存放主程序
logs  存放日志
conf  配置文件
webapps  存放网站页面  
lib  存放库文件
work  存放编译后页面文件
[root@web3 ~]#	cd /usr/local/tomcat/
[root@web3 tomcat]#	ls
[root@web3 tomcat]#	bin  conf  lib  LICENSE  logs  NOTICE  RELEASE-NOTES  RUNNING.txt  temp  webapps  work
[root@web3 tomcat]#	vim conf/server.xml
#修改Host标签
151         <Host name="localhost" appBase="webapps"
152         unpackWARs="true" autoDeploy="true">
153         <!-- 新增匹配客户端访问路径/tomcat,网页指定/data/tomcat-->
			<Context  path="/tomcat"  docBase="/data/tomcat"  />
154
155         <!-- SingleSignOn valve, share authentication between web applications
156              Documentation at: /docs/config/valve.html -->
157         <!--
158         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
159         -->
160
161         <!-- Access log processes all example.
162              Documentation at: /docs/config/valve.html
163              Note: The pattern used is equivalent to using pattern="common" -->
164         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
165                prefix="localhost_access_log" suffix=".txt"
166                pattern="%h %l %u %t &quot;%r&quot; %s %b" />
167
168       </Host>

部署网页

[root@web3 tomcat]# mkdir -p /data/tomcat
[root@web3 tomcat]# echo "web3_tomcat_test~~~" > /data/tomcat/index.html

启动服务

[root@web3 tomcat]# bin/startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@web3 tomcat]# ss -utnlp | grep java
tcp    LISTEN     0      1      ::ffff:127.0.0.1:8005                 :::*                   users:(("java",pid=12113,fd=69))
tcp    LISTEN     0      100      :::8009                 :::*                   users:(("java",pid=12113,fd=53))
tcp    LISTEN     0      100      :::8080                 :::*                   users:(("java",pid=12113,fd=48))

本机测试访问

[root@web3 tomcat]# curl 192.168.44.176:8080/tomcat/
web3_tomcat_test~~~

nginx反向代理部署

安装nginx

#进入nginx解压目录安装nginx
[root@nginx nginx]#	yum -y install make gcc psmisc  pcre-devel openssl openssl-devel
#部署加密网站需要--with-http_ssl_module模块,本次虽含有此模块但未使用
[root@nginx nginx]#	./configure --with-http_ssl_module
[root@nginx nginx]#	make && make install

修改配置文件,指定要代理的网站

#进入nginx安装目录
[root@nginx nginx]#	cd /usr/local/nginx/
#修改配置文件,指定要代理的网站
[root@nginx nginx]#	vim conf/nginx.conf
    #gzip  on;

    server {
        #nginx监听的端口默认80
        listen       80;
        #访问的域名
        server_name  www.nginx_proxy.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
		#默认的匹配,未做修改
        location / {
            root   html;
            index  index.html index.htm;
        }
        #指定代理的网站
        #web1
        location /web1 {
            proxy_pass http://192.168.44.174;
        }
        #web2
        location /web2 {
            proxy_pass http://192.168.44.175;
        }
        #web3
 		location /tomcat {
            proxy_pass http://192.168.44.176:8080;
        }

        #error_page  404              /404.html;

启动服务

#启动服务
[root@nginx nginx]#	sbin/nginx 
[root@nginx nginx]#	ss -utnlp | grep nginx
tcp    LISTEN     0      128       *:80                    *:*                   users:(("nginx",pid=16493,fd=6),("nginx",pid=3980,fd=6))

测试访问

使用ip访问

#使用ip访问
[root@nginx nginx]# curl 192.168.44.173
I am nginx_proxy~~~
[root@nginx nginx]# curl 192.168.44.173/web1/
 web1_test~~~
[root@nginx nginx]# curl 192.168.44.173/web2/
web2_test~~~
[root@nginx nginx]# curl  192.168.44.173/tomcat/
web3_tomcat_test~~~

使用域名访问

#使用域名访问
#添加本机域名解析
[root@nginx nginx]# vim /etc/hosts
#追加一行
192.168.44.173  www.nginx_proxy.com
[root@nginx nginx]# curl www.nginx_proxy.com
I am nginx_proxy~~~
[root@nginx nginx]# curl www.nginx_proxy.com/web1/
 web1_test~~~
[root@nginx nginx]# curl www.nginx_proxy.com/web2/
web2_test~~~
[root@nginx nginx]# curl  www.nginx_proxy.com/tomcat/
web3_tomcat_test~~~

windows真机使用浏览器域名访问

#windows真机使用浏览器访问
进入C:\Windows\System32\drivers\etc
修改hosts文件,追加一行
192.168.44.173 www.nginx_proxy.com
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。 Nginx的特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页伺服器中表现较好.目前中国大陆使用nginx网站用户有:新浪、网易、 腾讯,另外知名的微网志Plurk也使用nginxNginx 可以在大多数 Unix like OS 上编译运行,并有 Windows 移植版。目前 Nginx 的1.0.0稳定版已发布,开发版本为0.9.x,稳定版为 0.8.x,历史稳定版为 0.7.x,建议使用 0.8系列作为生产版本。 Nginx 的源代码使用 2-clause BSD-like license。 Nginx 是一个很牛的高性能Web和反向代理服务器,它具有很多非常优越的特性: 在高连接并发的情况下,Nginx是Apache服务器不错的替代品:Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一。能够支持高达 50,000 个并发连接数的响应,感谢Nginx为我们选择了 epoll and kqueue作为开发模型。 Nginx作为负载均衡服务器Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可以支持作为 HTTP代理服务器对外进行服务。Nginx采用C进行编写,不论是系统资源开销还是CPU使用效率都比 Perlbal 要好很多。 作为邮件代理服务器Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last. fm 描述了成功并且美妙的使用经验。 Nginx 是一个安装非常的简单,配置文件非常简洁(还能够支持perl语法),Bugs非常少的服务器Nginx 启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够不间断服务的情况下进行软件版本的升级。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值