咨询:Windows 2012服务器IIS 8中路由Java Web服务至Tomcat的方案
Absolutely! You can absolutely set up IIS 8 to act as a reverse proxy for Tomcat, routing requests to your Java web services while keeping your existing .NET services running smoothly on IIS. As someone who’s navigated mixing IIS and Java stacks before, here’s a straightforward, step-by-step breakdown tailored to your Windows 2012 setup:
First up, you’ll need two key tools to make the reverse proxy work: URL Rewrite and Application Request Routing (ARR). Here’s how to get them installed:
- Open Server Manager > Add Roles and Features
- Under Web Server (IIS) > Web Server > Application Development, check the box for CGI (it’s sometimes required for ARR to function properly)
- Under Web Server (IIS) > Management Tools, select URL Rewrite and Application Request Routing. If they don’t appear in the default list, you can download them directly from the IIS official site (just search for "IIS URL Rewrite download" and "IIS ARR download" to find the right packages for Windows 2012)
Since IIS is already using port 80 (and likely 443 for HTTPS), you’ll want Tomcat to listen on a separate, local-only port to avoid conflicts. Here’s how to tweak its config:
- Open Tomcat’s
conf/server.xmlfile in a text editor - Find the
<Connector>tag for HTTP/1.1 (usually near the top of the file) - Update the
portto something like8080, and addaddress="127.0.0.1"so Tomcat only accepts requests from the local server (this is more secure, as external traffic will go through IIS first) - Example connector config:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" address="127.0.0.1"/>
- Save the file and restart Tomcat to apply the changes
Now it’s time to tell IIS to send specific requests to Tomcat. Here’s the process:
- Open IIS Manager, right-click your server (or a specific site if you want to isolate Java routes from your .NET services) and select Application Request Routing > Server Proxy Settings
- Check the box for Enable proxy and click Apply
- Next, create a URL Rewrite rule to route traffic:
- Navigate to the site where you want to add the rule (could be your existing .NET site or a new dedicated site)
- Double-click URL Rewrite > Add Rule(s) > Reverse Proxy
- In the Inbound Rule section:
- Enter Tomcat’s local address (e.g.,
http://localhost:8080) as the destination - If you want to route only specific paths (like
/java-api/*to Tomcat, leaving your .NET endpoints untouched), adjust the pattern. For example, use a pattern like^java-api/(.*)and set the rewrite URL tohttp://localhost:8080/java-api/{R:1} - Make sure Append query string is checked so any query parameters are passed through to Tomcat
- Enter Tomcat’s local address (e.g.,
- Click OK to save the rule
- Deploy your Java web service to Tomcat (drop the WAR file into Tomcat’s
webappsfolder, or use the Tomcat Manager app to deploy it) - Access the service via IIS: if your IIS site is at
http://your-server-domain, and you set up the rule for/java-api, try visitinghttp://your-server-domain/java-api/your-endpoint - Verify that the request is successfully routed to Tomcat, and that your existing .NET services still work as expected
If you want your Java services to use HTTPS:
- First set up SSL in IIS by binding an SSL certificate to your IIS site
- You have two options here:
- IIS handles SSL termination: Let IIS accept HTTPS requests, then route them internally as HTTP to Tomcat (this is simpler, as you only manage SSL in one place)
- Pass HTTPS to Tomcat: Configure Tomcat to use SSL (update
server.xmlwith your certificate details, use port 8443) and adjust the rewrite rule to route tohttps://localhost:8443
A quick note about Tomcat connectors: You might have heard of the ISAPI Redirector (mod_jk) as another way to connect IIS and Tomcat. While it’s still a valid option, using ARR and URL Rewrite is more modern and easier to configure for reverse proxy scenarios—especially if you’re more comfortable with Java than IIS. The ISAPI Redirector requires manual setup of worker files and ISAPI filters, so ARR is generally the recommended approach these days.
内容的提问来源于stack exchange,提问作者JustinM

