簡體   English   中英

無法遠程訪問 tomcat 服務器

[英]Can't reach tomcat server remotely

我在 Google Compute Engine 上使用 VM,我選擇了 g1-small 機器。

我安裝了 tomcat 服務器。 服務器確實運行,但我無法在我的 web 瀏覽器上訪問它。

我還安裝了 httpd,我可以在瀏覽器上訪問端口 80,但不能訪問 8080

這是我的開放端口:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1180/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1198/master         
tcp6       0      0 :::22                   :::*                    LISTEN      1180/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1198/master         
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      11470/java          
tcp6       0      0 :::8080                 :::*                    LISTEN      11470/java          
tcp6       0      0 :::80                   :::*                    LISTEN      11319/httpd

這是我的 tomcat.service 文件:

[Unit]
Description=Tomcat 8.5 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/jre"

Environment="CATALINA_BASE=/opt/tomcat/apache-tomcat-8.5.56"
Environment="CATALINA_HOME=/opt/tomcat/apache-tomcat-8.5.56"
Environment="CATALINA_PID=/opt/tomcat/apache-tomcat-8.5.56/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/apache-tomcat-8.5.56/bin/startup.sh
ExecStop=/opt/tomcat/apache-tomcat-8.5.56/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

我已經使用命令將端口 8080 添加到防火牆

firewall-cmd --zone=public --permanent --add-port=8080/tcp
firewall-cmd --reload

但是當我列出防火牆設置時,我得到了這個

trusted (active)
 target: ACCEPT
 icmp-block-inversion: no
 interfaces: eth0
 sources: 
 services: http https
 ports: 
 protocols: 
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 

要解決您的問題,您應該配置 GCP 防火牆以允許入口連接到您的 Tomcat 服務器。

查看文檔配置防火牆規則並按照說明通過控制台或命令行創建防火牆入口規則

gcloud compute firewall-rules create tomcat-server-allow-ingress --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:8080 --source-ranges=0.0.0.0/0 --target-tags=tomcat-server

我建議您將0.0.0.0/0替換為您的 IP,並使用網絡標簽將您的規則直接應用於您的 VM 實例:

gcloud compute instances add-tags tomcat-server --zone=europe-west3-a --tags=tomcat-server

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM