tomcat代理的設定
NT的實現
yum -y install nginx 安裝Nginx
cd /etc/nginx/conf.d/
vim tomcat.conf
server {
listen 80;
server_name www.chenxi.com;
location / {
proxy_pass http://127.0.0.1; 定義只要非.jsp與do檔案結尾的都訪問本機,也就是動靜分離
}
location ~* \.(jsp|do)$ {
proxy_pass http://www.chenxis.com:8080;
}
}
server {
listen 80;
server_name www.chenxit.com;
location / {
proxy_pass http://www.chenxid.com:8080;
}
}
getenforce 檢視SELinux策略
setenforce 0 關閉SELinux策略
[root@localhost conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost conf.d]#systemctl start nginx
[root@localhost conf.d]# ss -lnt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 100 :::8080 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 100 :::8009 :::*
[root@localhost conf.d]# vim /etc/hosts 配置本地host解析檔案
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.251.203 www.chenxis.com www.chenxid.com
------------------------------------------------------------------------------------------------------------
tomcat的設定
<Host name="www.chenxid.com" appBase="webapps" 預設tomcat主頁
unpackWARs="true" autoDeploy="true">
</Host>
<Host name="www.chenxis.com" appBase="/data/webapps" 定義一個網頁的目錄
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="chenxis_access_log." suffix=".log"
pattern="%h %l %u %t "%r" %s %b" />
[root@centos7 tomcat]# cd /data/webapps
[root@centos7 webapps]# ls ROOT/
classes index.jsp lib META-INF WEB-INF
客戶端測試
以.jsp結尾
AT的實現
[root@localhost conf.d]#yum -y install httpd 安裝httpd服務
[root@localhost conf.d]# httpd -M 檢視httpd的模組
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set t
he 'ServerName' directive globally to suppress this messageLoaded Modules:
core_module (static)
so_module (static)
http_module (static)
access_compat_module (shared)
actions_module (shared)
alias_module (shared)
allowmethods_module (shared)
auth_basic_module (shared)
auth_digest_module (shared)
authn_anon_module (shared)
authn_core_module (shared)
authn_dbd_module (shared)
authn_dbm_module (shared)
authn_file_module (shared)
authn_socache_module (shared)
authz_core_module (shared)
authz_dbd_module (shared)
authz_dbm_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_owner_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cache_module (shared)
cache_disk_module (shared)
data_module (shared)
dbd_module (shared)
deflate_module (shared)
dir_module (shared)
dumpio_module (shared)
echo_module (shared)
env_module (shared)
expires_module (shared)
ext_filter_module (shared)
filter_module (shared)
headers_module (shared)
include_module (shared)
info_module (shared)
log_config_module (shared)
logio_module (shared)
mime_magic_module (shared)
mime_module (shared)
negotiation_module (shared)
remoteip_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
slotmem_plain_module (shared)
slotmem_shm_module (shared)
socache_dbm_module (shared)
socache_memcache_module (shared)
socache_shmcb_module (shared)
status_module (shared)
substitute_module (shared)
suexec_module (shared)
unique_id_module (shared)
unixd_module (shared)
userdir_module (shared)
version_module (shared)
vhost_alias_module (shared)
dav_module (shared)
dav_fs_module (shared)
dav_lock_module (shared)
lua_module (shared)
mpm_prefork_module (shared)
proxy_module (shared) 代理模組必須存在,沒有的話手動啟動
lbmethod_bybusyness_module (shared)
lbmethod_byrequests_module (shared)
lbmethod_bytraffic_module (shared)
lbmethod_heartbeat_module (shared)
proxy_ajp_module (shared) ajp的代理模組
proxy_balancer_module (shared)
proxy_connect_module (shared)
proxy_express_module (shared)
proxy_fcgi_module (shared)
proxy_fdpass_module (shared)
proxy_ftp_module (shared)
proxy_http_module (shared) 確保此模組存在
proxy_scgi_module (shared)
proxy_wstunnel_module (shared)
systemd_module (shared)
cgi_module (shared)
httpd的代理模組:
proxy_module
proxy_http_module:適配http協議客戶端;
proxy_ajp_module:適配ajp協議客戶端;
Client (http) --> httpd (proxy_http_module)(http) --> tomcat (http connector)
Client (http) --> httpd (proxy_ajp_module)(ajp) --> tomcat (ajp connector)
Client (http) --> httpd (mod_jk)(ajp) --> tomcat (ajp connector)
[root@localhost conf.d]# vim tomcat-http.conf
<VirtualHost *:80>
ServerName www.chenxi.com
ServerAlias www.cx.com 定義一個別名
ProxyRequests Off 是否關閉正想代理off關閉
ProxyVia On響應是是否加一個手部
ProxyPreserveHost Off 是否將客戶端請求主機名傳遞後端主機on傳遞off不傳遞
<Proxy *>
Require all granted對本地所有代理功能都允許
</Proxy>
ProxyPass / http://www.chenxis.com:8080/表示你請求的內容是什麼後面內容就是什麼;建議一致,不一致重寫是會出問題
ProxyPassReverse / http://www.chenxis.com:8080/ 重寫後是否對新URL做代理
<Location />
Require all granted做授權2.4要求必須要授權的
</Location>
</VirtualHost>
客戶端的host檔案
客戶端測試
使用ajp協議實現at
[root@localhost conf.d]# vim tomcat-http.conf
<VirtualHost *:80>
ServerName www.chenxi.com
ServerAlias www.cx.com
ProxyRequests Off
ProxyVia On
ProxyPreserveHost Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / ajp://www.chenxis.com:8005/
ProxyPassReverse / ajp://www.chenxis.com:8005/
<Location />
Require all granted
</Location>
</VirtualHost>
[root@localhost conf.d]# systemctl restart httpd
[root@localhost conf.d]# ss -lnt
State Recv-Q Send-Q Local Address:Port Peer Addre
ss:Port LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
客戶端測試不支援把後端主機,只會把前段使用者請求的主機名傳給後端主機
<VirtualHost *:80>
ServerName www.chenxi.com
ServerAlias www.cx.com
ProxyRequests Off
ProxyVia On
ProxyPreserveHost Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / ajp://www.chenxis.com:8009/
ProxyPassReverse / ajp://www.chenxis.com:8009/
<Location />
Require all granted
</Location>
</VirtualHost>
[root@localhost conf.d]# systemctl restart httpd
[root@localhost conf.d]# ss -lnt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
客戶端測試
更改host檔案
訪問www.chenxis.com
實現NAT用jsp
[root@localhost yum.repos.d]# yum -y install nginx
[root@localhost conf.d]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# cat tomcat.conf Nginx的相關設定
server {
listen 80;
server_name www.chenxi.com;
location / {
proxy_pass http://127.0.0.1;
}
location ~* \.(jsp|do)$ {
proxy_pass http://www.chenxis.com:8080;
}
}
server {
listen 80;
server_name www.chenxit.com;
location / {
proxy_pass http://www.chenxid.com:8080;
}
}
[root@localhost conf.d]# vim tomcat-http.conf httpd端使用ajp代理
<VirtualHost *:80>
ServerName www.chenxi.com
ServerAlias www.cx.com
ProxyRequests Off 關閉正向代理
ProxyVia On
ProxyPreserveHost Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / ajp:/ http.chenxis.com:8009/
ProxyPassReverse / http://www.chenxis.com:8009/
<Location />
Require all granted
</Location>
</VirtualHost>
客戶端測試
實現NAT用httd的配置
http的相關配置
[root@localhost httpd]# vim /etc/httpd/conf.d/tomcat-http.conf
<VirtualHost *:80>
ServerName www.chenxi.com
ServerAlias www.cx.com
ProxyRequests Off
ProxyVia On
ProxyPreserveHost Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://www.chenxis.com:8080/
ProxyPassReverse / http://www.chenxis.com:8080/
<Location />
Require all granted
</Location>
</VirtualHost>
[root@localhost httpd]# systemctl restart httpd 重啟服務
Nginx服務不需要做什麼改動
客戶端測試
NTjijue的實現
HT客戶測試
http://172.16.250.236:9009/haproxy?stats
相關文章
- TOMCAT的Context設定TomcatContext
- Nginx 代理設定Nginx
- pnpm 設定代理NPM
- tomcat JVM 設定TomcatJVM
- Git中設定代理和取消代理Git
- Python代理IP的使用和代理池的設定Python
- npm 設定埠代理NPM
- nginx 反向代理設定Nginx
- Gradle 代理設定Gradle
- sdk更新代理設定
- anaconda 設定代理
- Tomcat 設定編碼Tomcat
- Python requests設定代理的方法Python
- 常用開發工具的代理設定
- 為YUM設定代理的方法 ccproxy
- Mac怎麼設定代理IP,蘋果系統設定http代理ip教程Mac蘋果HTTP
- MacOS設定終端代理Mac
- Nginx、haproxy反向代理設定Nginx
- 為終端設定代理
- git 設定和取消代理Git
- C# WebBrowser設定代理C#Web
- tomcat vm 引數設定Tomcat
- Tomcat記憶體設定Tomcat記憶體
- 為Tomcat設定自己的管理賬號Tomcat
- idea之設定web工程的TomcatIdeaWebTomcat
- 設定Tomcat的UTF-8編碼Tomcat
- 如何設定tomcat的非debug模式?Tomcat模式
- Python怎麼設定代理Python
- 為Docker容器設定http代理DockerHTTP
- Java怎麼設定代理使用?Java
- 為wget命令設定代理wget
- FindProxyForURL設定瀏覽器代理瀏覽器
- java程式設定http,socks代理JavaHTTP
- mumu模擬器設定代理
- tomcat設定記憶體大小Tomcat記憶體
- tomcat https訪問設定TomcatHTTP
- 路由設定代理IP的三大作用路由
- tomcat 配置nginx 反向代理TomcatNginx