1リバースプロキシ
1.1リバースプロキシとは何ですか
フォワードプロキシ
リバースプロキシ:
リバースプロキシ(リバースプロキシ)モードでは、その後、インターネット上の接続要求を受け入れるようにプロキシサーバーを参照将请求转发给内部网络上的服务器
し、サーバから得られた結果でインターネット接続上の要求元のクライアントに戻り、などの外部プロキシサーバが表示されますプロキシサーバーを逆に。
サービスを提供するサーバー、プロキシサーバーを判断し逆にします。
ドメイン名の要求に応じて、Nginx
このように、サーバの実際のアドレスを隠し、対応するサーバに要求を転送します。
リバースプロキシサーバはまた、サービスを提供していません
请求的转发
。
1.2リバースプロキシのメリット
リバースプロキシの利点:隐藏真实内部 ip 地址
アクセスするための要求nginx
、その後、(ネットワーク缶アクセス外)プロキシサーバーを使用してnginx
実サーバにリレーサーバを。
1.3 Nginx
リバースプロキシを達成するために
2人のドメイン名が同じにポイントnginx
サーバー、別のユーザーが異なるWebコンテンツを表示するには、ドメイン名にアクセスします。
- 2人のドメイン名がある
www.e3mall.com
とwww.taotao.com
nginx
サーバーは、仮想マシンを使用しています。192.168.153.11
ステップ1:2がインストールし
tomcat
実行していた8080
と8081
ポート。
ダウンロードTomcat
:
wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.23/bin/apache-tomcat-8.0.23.tar.gz
解凍:
tar -zxvf apache-tomcat-8.0.23.tar.gz
2をコピーしますTomcat
:
cp apache-tomcat-8.0.23 tomcat-1 -r
cp apache-tomcat-8.0.23 tomcat-2 -r
[root@weaver-1 ~]# ll
total 8872
-rw-------. 1 root root 1801 Jan 6 15:48 anaconda-ks.cfg
drwxr-xr-x. 9 root root 160 Mar 18 03:43 apache-tomcat-8.0.23
-rw-r--r--. 1 root root 9076980 May 19 2015 apache-tomcat-8.0.23.tar.gz
drwxr-xr-x. 9 root root 160 Mar 18 03:44 tomcat-1
drwxr-xr-x. 9 root root 160 Mar 18 03:44 tomcat-2
[root@weaver-1 ~]#
変更しtomcat-1
たポート番号です8001
。
vi tomcat-1/conf/server.xml
三つのポートを変更します。
# 8005 改为 8006
<Server port="8006" shutdown="SHUTDOWN">
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
......
# 8080 改为 8001
<Connector port="8001" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
......
# 8009 改为 8010
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
変更しtomcat-2
たポート番号です8002
。
vi tomcat-2/conf/server.xml
三つのポートを変更します。
# 8005 改为 8007
<Server port="8007" shutdown="SHUTDOWN">
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
......
# 8080 改为 8002
<Connector port="8002" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
......
# 8009 改为 8011
<Connector port="8011" protocol="AJP/1.3" redirectPort="8443" />
ステップ2:スタート2
tomcat
:
tomcat-1/bin/startup.sh
tomcat-2/bin/startup.sh
[root@weaver-1 ~]# tomcat-1/bin/startup.sh
Using CATALINA_BASE: /root/tomcat-1
Using CATALINA_HOME: /root/tomcat-1
Using CATALINA_TMPDIR: /root/tomcat-1/temp
Using JRE_HOME: /usr/java/jdk1.8.0_131
Using CLASSPATH: /root/tomcat-1/bin/bootstrap.jar:/root/tomcat-1/bin/tomcat-juli.jar
Tomcat started.
[root@weaver-1 ~]# tomcat-2/bin/startup.sh
Using CATALINA_BASE: /root/tomcat-2
Using CATALINA_HOME: /root/tomcat-2
Using CATALINA_TMPDIR: /root/tomcat-2/temp
Using JRE_HOME: /usr/java/jdk1.8.0_131
Using CLASSPATH: /root/tomcat-2/bin/bootstrap.jar:/root/tomcat-2/bin/tomcat-juli.jar
Tomcat started.
[root@weaver-1 ~]#
ビュースタートアップの成功:
tail -f tomcat-1/logs/catalina.out
tail -f tomcat-2/logs/catalina.out
テスト:
ウェルカムページを変更します。
vi tomcat-1/webapps/ROOT/index.jsp
vi tomcat-2/webapps/ROOT/index.jsp
```bash
<h1>${pageContext.servletContext.serverInfo} - 8001</h1>
<h1>${pageContext.servletContext.serverInfo} - 8002</h1>
リフレッシュのページ:
ステップ3:設定リバースプロキシサーバ
変更するnginx
設定ファイルを:
vi /usr/local/nginx/conf/nginx.conf
#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;
#access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
#gzip on;
server {
listen 80; # server监听的端口号
server_name localhost; # 配置域名
location / {
root html; # 拦截后,跳转根路径
index index.html index.htm; # 默认页面
}
}
############ 添加配置一
server {
listen 80;
server_name www.test1.com;
location / {
proxy_pass http://127.0.0.1:8001;
index index.html index.htm;
}
}
############ 添加配置二
server {
listen 80;
server_name www.test2.com;
location / {
proxy_pass http://127.0.0.1:8002;
index index.html index.htm;
}
}
}
次のように構成されましたか:
#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;
#access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
#gzip on;
server {
listen 80; # server监听的端口号
server_name localhost; # 配置域名
location / {
root html; # 拦截后,跳转根路径
index index.html index.htm; # 默认页面
}
}
############ 添加配置一
upstream test1 {
server 127.0.0.1:8001;
}
server {
listen 80;
server_name www.test1.com;
location / {
proxy_pass http://test1;
index index.html index.htm;
}
}
############ 添加配置二
upstream test2 {
server 127.0.0.1:8002;
}
server {
listen 80;
server_name www.test2.com;
location / {
proxy_pass http://test2;
index index.html index.htm;
}
}
}
ステップ4:
nginx
設定ファイルを再ロードします。
/usr/local/nginx/sbin/nginx -s reload
ステップ5:設定したドメイン名
マシンでhostsファイルにドメイン名とIPとの間のマッピングを追加します。
192.168.153.11 www.test.com
192.168.153.11 www.test1.com
192.168.153.11 www.test2.com
テスト: