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
相關文章
- 代理的設定
- idea之設定web工程的TomcatIdeaWebTomcat
- anaconda 設定代理
- pnpm 設定代理NPM
- docker 設定代理Docker
- linux 設定代理Linux
- Python代理IP的使用和代理池的設定Python
- tomcat vm 引數設定Tomcat
- Python requests設定代理的方法Python
- 為Tomcat設定自己的管理賬號Tomcat
- npm 設定埠代理NPM
- vite 設定網路代理Vite
- ubuntu 給 apt 設定代理UbuntuAPT
- MacOS設定終端代理Mac
- Python怎麼設定代理Python
- Mac怎麼設定代理IP,蘋果系統設定http代理ip教程Mac蘋果HTTP
- tomcat 配置nginx 反向代理TomcatNginx
- centos7 設定tomcat自啟動CentOSTomcat
- solr搜尋報錯,tomcat maxHttpHeaderSize 設定SolrTomcatHTTPHeader
- 為Docker容器設定http代理DockerHTTP
- mumu模擬器設定代理
- Java怎麼設定代理使用?Java
- JAVA設定http請求代理JavaHTTP
- 設定windows系統下的tomcat開機自啟WindowsTomcat
- 路由設定代理IP的三大作用路由
- Linux配置JavaEE環境 Linux中安裝JDK、Tomcat、mysql 設定Tomcat自啟動、設定mysql自啟動LinuxJavaJDKTomcatMySql
- Linux之換源、Tomcat及jdk的安裝配置和設定Tomcat自動啟動LinuxTomcatJDK
- Python爬蟲技巧---設定代理IPPython爬蟲
- Mac OS iTerm 控制檯設定代理Mac
- iOS 設定代理(Proxy)方案總結iOS
- tomcat配置環境變數win10怎樣設定_win10如何設定tomcat配置環境變數Tomcat變數Win10
- selenium+python設定爬蟲代理IP的方法Python爬蟲
- 透過adb設定模擬器的HTTP代理HTTP
- 使用了Buzz庫的HttpClient類來設定代理HTTPclient
- sbt卡住的解決辦法,sbt設定代理
- 如何用海外HTTP代理設定python爬蟲代理ip池?HTTPPython爬蟲
- tomcat 設定session過期時間(四種方式)TomcatSession
- IDEA如何建立web專案及tomcat設定等IdeaWebTomcat
- SOCKS代理的定義