如何在多个URL上使用同一Tomcat实例?配置问题求助
quietude.anotherdomain.com Access Issue with Tomcat & Apache Hey there, let's break down why your new domain quietude.anotherdomain.com isn't working while opxxx01.domain.com runs perfectly. Based on your environment details (RHEL 7.4, Tomcat 8.5.30, Apache 2.4.6) and the config you shared, here are the key checks and fixes to get this sorted:
1. Verify DNS & Network Reachability
First, rule out basic network issues:
- Run
nslookup quietude.anotherdomain.comordig quietude.anotherdomain.comon your local machine or the server itself. Make sure the returned IP matches your serveropxxx01's public/private IP. If not, you'll need to update the DNS record forquietude.anotherdomain.comto point to the correct IP. - Check your server's firewall (either
firewalldoriptables) to ensure the ports used for access (80/443 for Apache, or 8080 for direct Tomcat access) are open. For example, withfirewalld:sudo firewall-cmd --add-port=80/tcp --permanent sudo firewall-cmd --reload
2. Fix Apache Reverse Proxy Configuration
Since you have Apache 2.4.6 running, it's likely you're using it as a reverse proxy to Tomcat (direct Tomcat access on 8080 isn't typical for production). You need to add a VirtualHost for your new domain to forward requests to Tomcat:
- Create or edit an Apache config file (e.g.,
/etc/httpd/conf.d/quietude.conf) with this content:<VirtualHost *:80> ServerName quietude.anotherdomain.com # Forward all requests to Tomcat's port (adjust if you use a different port) ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ # Optional: Logs for the new domain ErrorLog /var/log/httpd/quietude_error.log CustomLog /var/log/httpd/quietude_access.log combined </VirtualHost> - Enable required Apache modules (if not already enabled):
sudo yum install httpd-mod_proxy httpd-mod_proxy_http sudo systemctl restart httpd - Confirm your original domain
opxxx01.domain.comhas a similar VirtualHost setup—this ensures consistency in how Apache handles both domains.
3. Tweak Tomcat Host & Connector Settings
Your Tomcat Host config looks mostly right, but let's check a few details:
- In your
server.xml, ensure theConnectorelement isn't bound to a specific IP. Theaddressattribute should be set to0.0.0.0or omitted entirely, so Tomcat accepts requests from all sources (including Apache):<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" address="0.0.0.0" /> - If your app is deployed under a specific context (not the ROOT app), you can add a
Contextentry to your new Host to set it as the default:<Host name="quietude.anotherdomain.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="quietude_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b %S %D %F" /> <Context path="" docBase="your-app-folder" reloadable="true" /> </Host> - Check Tomcat logs (
logs/quietude_access_log*.txtandlogs/catalina.out) to see if requests are reaching Tomcat. If logs show no incoming requests, the issue is upstream (DNS/Apache). If there are errors, the log details will point to the root cause (e.g., missing app deployment).
4. Test with Local Hosts File (For Debugging)
If you're testing in a non-production environment, bypass DNS to isolate the issue:
- On your local machine, edit the
hostsfile:- Windows:
C:\Windows\System32\drivers\etc\hosts - Linux/macOS:
/etc/hosts
- Windows:
- Add a line like:
[your-server-ip] quietude.anotherdomain.com - Try accessing
quietude.anotherdomain.comagain—if it works, the problem is with your DNS record.
内容的提问来源于stack exchange,提问作者Jeremy

