Nginx反向代理

目錄

  • 一.簡介
    • 1.反向代理
  • 二.案例
    • 1.案例1
    • 2.案例2

一.簡介

1.反向代理

1.1反向代理: 是指代理服務器來接收Internet上的客戶端請求,然后將請求轉發給內部網絡上的服務器,并將從服務器上得到的結果返回給客戶端。此時代理服務器對外就表現為一個反向代理服務器。
反向代理客戶端不知道服務器的信息,隱藏了服務器的信息

1.2正向代理:是一個位于客戶端和原始服務器之間的服務器,為了從原始服務器獲得內容。客戶端向代理發送一個請求并指定目標(原始服務器),然后代理向原始服務器轉發并獲得的內容返回給客戶端
正向代理服務器不知道客戶端的信息,隱藏了客戶端的信息

二.案例

1.案例1

1.1實現思路
在這里插入圖片描述
1.2實現步驟
1.2.1Nginx配置

#配置文件中修改
vim /usr/local/nginx/conf/nginx.conf
server {listen       80;server_name  10.10.100.222;#charset koi8-r;#access_log  logs/host.access.log  main;location / {proxy_pass http://127.0.0.1:8080;root   html;index  index.html index.htm;}#檢測語法是否正確
[root@localhost sbin]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful#重新加載nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload

1.2.2搭建tomcat

tomcat包和jdk包
鏈接:https://pan.baidu.com/s/12n0LNdXiXIJh-GNQwp2WNw
提取碼:7ptr
–來自百度網盤超級會員V1的分享
鏈接:https://pan.baidu.com/s/1yuBmzZ76QShBfBnrrgDLfA
提取碼:hk96
–來自百度網盤超級會員V1的分享

安裝jdk環境

#先創建java文件目錄,如果已存在就不用創建
mkdir -p /usr/local/java#解壓到java文件目錄
tar -vzxf jdk-8u161-linux-x64.tar.gz -C /usr/local/java/#配置環境變量
vi /etc/profile
export JAVA_HOME=/usr/local/java/jdk1.8.0_11
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin#生效環境變量
source /etc/profile

下載Tomcat、解壓Tomcat、安裝Tomcat、啟動Tomcat

#解壓tomcat
tar -zxvf apache-tomcat-9.0.78.tar.gz#安裝tomcat
mv apache-tomcat-9.0.78 /usr/local/tomcat#啟動tomcat
/usr/local/tomcat/bin/startup.sh

1.3測試
可以看到tomcat的界面,實際上是訪問ngnix跳轉到tomcat的8080端口
在這里插入圖片描述

2.案例2

2.1實現思路
在這里插入圖片描述
2.2實現步驟

#修改配置文件
server {listen       80;server_name  10.10.100.222;#charset koi8-r;#access_log  logs/host.access.log  main;location ~/aaa/ {proxy_pass http://127.0.0.1:8080;}location ~/bbb/ {proxy_pass http://127.0.0.1:8081;}
}#重新加載nginx
/usr/local/nginx/sbin/nginx -s reload

2.2.1拷貝兩個Tomcat,將其中一個的端口信息修改為8081

#拷貝兩個tomcattar -zxvf apache-tomcat-9.0.78.tar.gzmv apache-tomcat-9.0.78 /usr/local/tomcat1tar -zxvf apache-tomcat-9.0.78.tar.gzmv apache-tomcat-9.0.78 /usr/local/tomcat2#刪除tomcat2下面的配置
rm -f /usr/local/tomcat2/conf/server.xml
#添加新配置文件
vi /usr/local/tomcat2/conf/server.xml
<!-- Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements.  See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License.  You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.-->
<!--  Note:  A "Server" is not itself a "Container", so you may notdefine subcomponents such as "Valves" at this level.Documentation at /docs/config/server.html-->
<Server port="8006" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<!--  Security listener. Documentation at /docs/config/listeners.html<Listener className="org.apache.catalina.security.SecurityListener" />-->
<!--  APR library loader. Documentation at /docs/apr.html  -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/>
<!--  Prevent memory leaks due to use of particular java/javax APIs -->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<!--  Global JNDI resourcesDocumentation at /docs/jndi-resources-howto.html-->
<GlobalNamingResources>
<!--  Editable user database that can also be used byUserDatabaseRealm to authenticate users-->
<Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml"/>
</GlobalNamingResources>
<!--  A "Service" is a collection of one or more "Connectors" that sharea single "Container" Note:  A "Service" is not itself a "Container",so you may not define subcomponents such as "Valves" at this level.Documentation at /docs/config/service.html-->
<Service name="Catalina">
<!-- The connectors can use a shared executor, you can define one or more named thread pools -->
<!-- <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"maxThreads="150" minSpareThreads="4"/>-->
<!--  A "Connector" represents an endpoint by which requests are receivedand responses are returned. Documentation at :Java HTTP Connector: /docs/config/http.htmlJava AJP  Connector: /docs/config/ajp.htmlAPR (HTTP/AJP) Connector: /docs/apr.htmlDefine a non-SSL/TLS HTTP/1.1 Connector on port 8080-->
<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" maxParameterCount="1000"/>
<!--  A "Connector" using the shared thread pool -->
<!-- <Connector executor="tomcatThreadPool"port="8081" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443"maxParameterCount="1000"/>-->
<!--  Define an SSL/TLS HTTP/1.1 Connector on port 8443This connector uses the NIO implementation. The defaultSSLImplementation will depend on the presence of the APR/nativelibrary and the useOpenSSL attribute of the AprLifecycleListener.Either JSSE or OpenSSL style configuration may be used regardless ofthe SSLImplementation selected. JSSE style configuration is used below.-->
<!-- <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"maxThreads="150" SSLEnabled="true"maxParameterCount="1000"><SSLHostConfig><Certificate certificateKeystoreFile="conf/localhost-rsa.jks"type="RSA" /></SSLHostConfig></Connector>-->
<!--  Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2This connector uses the APR/native implementation which always usesOpenSSL for TLS.Either JSSE or OpenSSL style configuration may be used. OpenSSL styleconfiguration is used below.-->
<!-- <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"maxThreads="150" SSLEnabled="true"maxParameterCount="1000"><UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" /><SSLHostConfig><Certificate certificateKeyFile="conf/localhost-rsa-key.pem"certificateFile="conf/localhost-rsa-cert.pem"certificateChainFile="conf/localhost-rsa-chain.pem"type="RSA" /></SSLHostConfig></Connector>-->
<!--  Define an AJP 1.3 Connector on port 8009  -->
<!-- <Connector protocol="AJP/1.3"address="::1"port="8010"redirectPort="8443"maxParameterCount="1000"/>-->
<!--  An Engine represents the entry point (within Catalina) that processesevery request.  The Engine implementation for Tomcat stand aloneanalyzes the HTTP headers included with the request, and passes themon to the appropriate Host (virtual host).Documentation at /docs/config/engine.html  -->
<!--  You should set jvmRoute to support load-balancing via AJP ie :<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">-->
<Engine name="Catalina" defaultHost="localhost">
<!-- For clustering, please take a look at documentation at:/docs/cluster-howto.html  (simple how to)/docs/config/cluster.html (reference documentation)  -->
<!-- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>-->
<!--  Use the LockOutRealm to prevent attempts to guess user passwordsvia a brute-force attack  -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!--  This Realm uses the UserDatabase configured in the global JNDIresources under the key "UserDatabase".  Any editsthat are performed against this UserDatabase are immediatelyavailable for use by the Realm.   -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<!--  SingleSignOn valve, share authentication between web applicationsDocumentation at: /docs/config/valve.html  -->
<!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" />-->
<!--  Access log processes all example.Documentation at: /docs/config/valve.htmlNote: The pattern used is equivalent to using pattern="common"  -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b"/>
</Host>
</Engine>
</Service>
</Server>
#創建文件夾和文件mkdir -p /usr/local/tomcat1/webapps/aaamkdir -p /usr/local/tomcat2/webapps/bbbecho "<h1>This is 8080 Port</h1>" > /usr/local/tomcat1/webapps/aaa/a.htmlecho "<h1>This is 8081 Port</h1>" > /usr/local/tomcat2/webapps/bbb/b.html
#啟動tomcat
/usr/local/tomcat1/bin/startup.sh
/usr/local/tomcat2/bin/startup.sh

2.3測試
在這里插入圖片描述
在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/41457.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/41457.shtml
英文地址,請注明出處:http://en.pswp.cn/news/41457.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

循環隊列的實現(c語言)

前言 循環隊列是隊列的一種特殊的結構&#xff0c;在生產者——消費者模型中常常使用它&#xff0c; 它在邏輯上是一個環形的連續的結構。在物理可以使用數組來實現。 目錄 1.循環隊列的邏輯結構 2.空的循環隊列和滿的循環隊列 3.循環隊列插入和刪除 4.代碼實現 …

淺談Redis的maxmemory設置以及淘汰策略

推薦閱讀 AI文本 OCR識別最佳實踐 AI Gamma一鍵生成PPT工具直達鏈接 玩轉cloud Studio 在線編碼神器 玩轉 GPU AI繪畫、AI講話、翻譯,GPU點亮AI想象空間 資源分享 「java、python面試題」來自UC網盤app分享&#xff0c;打開手機app&#xff0c;額外獲得1T空間 https://dr…

音視頻實時通話解決方案

1、問題提出 想要實現音視頻通話,對于大部分人可能會覺得很難,但是實際上,有些事情并沒有大家想的那樣困難,只要功夫深,鐵杵磨成針。 機緣巧合下,在業務中,我也遇到了一個業務場景需要實現音視頻通話,我們不可能自己從零開始干,我本次用到的核心是WebRTC。 2、WebRT…

治療偏頭痛等亞疼痛的遠程電神經調控(REN)設備

原文鏈接&#xff1a; NERIVIO CE標志適應癥擴展到青少年和成人偏頭痛的預防和急性治療 (prnewswire.com) 公司官網&#xff1a; Homepage - Theranica APP下載鏈接&#xff1a; Migraine Headache Treatment - Nerivio 使用過程問題&#xff1a; 常見問題 - 無藥物偏頭痛兩…

統計XML標注文件中各標注類別的標簽數量

目標檢測任務重&#xff0c;擔心數據集中各標簽類別不均衡&#xff0c;想統計XML標注文件中各標注類別的標簽數量&#xff0c;可以使用以下腳本&#xff1a; import os import glob import xml.etree.ElementTree as etdef count_labels(source_dir):file_list glob.glob(os.…

Flink狀態和狀態管理

1.什么是狀態 官方定義&#xff1a;當前計算流程需要依賴到之前計算的結果&#xff0c;那么之前計算的結果就是狀態。 這句話還是挺好理解的&#xff0c;狀態不只存在于Flink&#xff0c;也存在生活的方方面面&#xff0c;比如看到一個認識的人&#xff0c;如何識別認識呢&am…

神經網絡基礎-神經網絡補充概念-24-隨機初始化

由來 在神經網絡的訓練過程中&#xff0c;權重和偏差的初始值對模型的性能和訓練過程的收斂速度都有影響。隨機初始化是一種常用的權重和偏差初始值設置方法&#xff0c;它有助于打破對稱性&#xff0c;避免網絡陷入局部最優解。 概念 當所有權重和偏差都被設置為相同的初始…

Python Web框架:Django、Flask和FastAPI巔峰對決

今天&#xff0c;我們將深入探討Python Web框架的三巨頭&#xff1a;Django、Flask和FastAPI。無論你是Python小白還是老司機&#xff0c;本文都會為你解惑&#xff0c;帶你領略這三者的魅力。廢話不多說&#xff0c;讓我們開始這場終極對比&#xff01; Django&#xff1a;百…

web基礎入門和php語言基礎入門 二

web基礎入門和php語言基礎入門 二 MySQL入門-續MySQL之數據查詢操作MySQL其他知識點 php語言基礎入門認識PHPPHP的工作流程安裝PHP環境認識一個PHP程序PHP基礎知識點進入正題 PHP與WEB交互PHP與MySQL交互總結 MySQL入門-續 MySQL之數據查詢操作 WHERE 子句&#xff0c;條件限…

# 快速評估立功科技基于S32K324的TMS方案

文章目錄 1.前言2.立功科技的TMS方案介紹2.1 介紹資料2.2 簡要介紹 3.S32K3_TriMotor評估板測試3.1 環境搭建S32 Design Studio for S32 Platform 3.4安裝RTD 2.0.0安裝Freemaster 3.2 3.2 例程測試3.3 例程適配3.4 雙核燒錄3.5 測試 1.前言 最近和一些做汽車水泵/風機的客戶交…

算法概述-Java常用算法

算法概述-Java常用算法 1、算法概念2、算法相關概念3、算法的性能評價4、算法應用歸納 1、算法概念 廣泛算法定義&#xff1a;算法是模型分析的一組可行性的、確定的和有窮的規則。 經典算法特征&#xff1a;有窮性、確切性、輸入、輸出和可行性。 常用的算法包括遞推、遞歸、窮…

maven如何建立JavaWeb項目并連接數據庫,驗證登錄

這里是建立建立web項目&#xff1a;Maven如何創建Java web項目&#xff08;純干貨版&#xff09;&#xff01;&#xff01;&#xff01;_明天更新的博客-CSDN博客 我們主要演示如何連接數據庫驗證登錄。 1.在webapp目錄下創建我們的登錄頁面&#xff1a;index.jsp 還需要再…

Android漏洞之戰——整體加殼原理和脫殼技巧詳解

一、前言 為了幫助更加方便的進行漏洞挖掘工作&#xff0c;前面我們通過了幾篇文章詳解的給大家介紹了動態調試技術、過反調試技術、Hook技術、過反Hook技術、抓包技術等&#xff0c;掌握了這些可以很方便的開展App漏洞挖掘工作&#xff0c;而最后我們還需要掌握一定的脫殼技巧…

opencv基礎:幾個常用窗口方法

開始說了一些opencv中的一些常用方法。 namedWindow方法 在OpenCV中&#xff0c;namedWindow函數用于創建一個窗口&#xff0c;并給它指定一個名字。這個函數的基本語法如下&#xff1a; import cv2cv2.namedWindow(窗口名稱, 標識 )窗口名稱&#xff1a;其實窗口名稱&…

Azure創建自定義VM鏡像

創建一個虛擬機&#xff0c;參考 https://blog.csdn.net/m0_48468018/article/details/132267096&#xff0c;入站端口開啟80&#xff0c;22 進行遠程遠程連接 使用CLI命令部署NGINX,輸入如下命令 sudo su apt-get update -y apt-get install nginx git -y最后的效果 4. 關閉…

非結構化數據庫-MinIO基本集成

是什么 MinIO 是一個高性能的分布式對象存儲服務&#xff0c;適合存儲非結構化數據&#xff0c;如圖片&#xff0c;音頻&#xff0c;視頻&#xff0c;日志等。對象文件最大可以達到5TB。 安裝啟動 mkdir -p /usr/local/minio cd /usr/local/minio# 下載安裝包 wget https:/…

pandas.errors.ParserError: Error tokenizing data. C error: out of memory

目錄 用pandas讀入數據的時候發現數據讀入時出錯了&#xff0c;數據量感覺也不是很大 十萬多條數據。電腦內存是16個G。報錯信息為&#xff1a;“ pandas.errors.ParserError: Error tokenizing data. C error: out of memory” 想想不對啊 昨天都可以順利的讀入&#xff0c;現…

你真的掌握了 Python 的七種參數了嗎?

不知道為什么網上總有人說 Python 的參數類型有 4 種啊&#xff0c;5 種啊&#xff0c;殊不知其實有 7 種。Python 的 7 種參數分別是 默認參數、位置參數、關鍵字參數、可變長位置參數、可變長關鍵字參數、僅位置參數 和 僅關鍵字參數。小白可能沒見過“可變長參數”&#xff…

lvs-dr模式

一&#xff0c;數據包流向&#xff1a; 1&#xff0c;cilent向目標vip發出請求&#xff0c;dir接收&#xff0c;此時ip報頭數據幀頭信息。 2&#xff0c;dir根據負載均衡算法給rs&#xff08;rip&#xff09;&#xff0c;將rip所在網卡的mac地址作為目標的mac地址&#xff0c;發…

深入解析Spring基本概念和核心思想

文章目錄 基本概念IoCIoc容器IoC理解IoC的步驟Spring中使用ioc的步驟 AopAop的理解Aop的步驟 控制反轉誰控制誰? 控制什么?為何叫反轉(對應于正向)?哪些方面反轉了?為何需要反轉? 依賴什么是依賴(按名稱理解、按動詞理解)? 誰依賴于誰? 為什么需要依賴? 依賴什么東西?…