Are you having trouble getting your Node.js application to run on IIS with a reverse proxy configuration? You're not alone. Many developers have run into the issue where their application works perfectly on localhost:3000, but they receive a "Cannot GET" error when trying to access it through IIS.
In this article, we'll go over the steps to properly configure Node.js to run on IIS with a reverse proxy, and troubleshoot the "Cannot GET" error. By the end of this article, you should have a solid understanding of how to get your Node.js application up and running on IIS.
Prerequisites
Before we begin, make sure you have the following:
- A working Node.js application
- IIS (Internet Information Services) installed on your Windows machine
- URL Rewrite and Application Request Routing modules for IIS
Step 1: Create a new website in IIS
Start by opening the IIS Manager. Right-click on "Sites" and select "Add Website...". Fill in the details as follows:
- Site name: Choose a name for your website
- Application pool: Choose an existing application pool or create a new one
- Physical path: Point to the directory where your Node.js application is located
- Binding: Set the hostname and port number (e.g.
myapp.local:80)
Step 2: Install and configure the reverse proxy
To enable reverse proxy functionality in IIS, you need to install the URL Rewrite and Application Request Routing modules. You can download them from the following links:
Once installed, open the IIS Manager, navigate to your website, and perform the following steps:
- Double-click "URL Rewrite"
- Click "Add Rule(s)..."
- Select "Reverse Proxy" and click "OK"
- Fill in the details as follows:
- Inbound rule name: Choose a name for your rule
- Reverse proxy URL:
http://localhost:3000 - Check "Enable SSL offloading" if your Node.js application is using HTTPS
Step 3: Troubleshooting the "Cannot GET" error
If you're still experiencing the "Cannot GET" error, there are a few things you can check:
- Make sure your Node.js application is listening on the correct IP address and port. By default, it should be listening on
localhostand port3000. You can check this by adding a line like this to your application:
console.log(`Listening on ${server.address().address}:${server.address().port}`);
- Check if your application has any issues with the reverse proxy configuration. You can test this by accessing your application directly through the reverse proxy URL (
http://myapp.local:80). If you see any errors, you may need to adjust your application's configuration. - Ensure that your application's routes are correctly defined. If you're using a framework like Express, make sure that the routes are properly defined and that there are no typos or other issues.
- Check if there are any issues with the URL Rewrite and Application Request Routing modules. Make sure they are properly installed and configured.
By following the steps outlined in this article, you should now have a working Node.js application running on IIS with a reverse proxy configuration. Remember to double-check your application's configuration and routes, and make sure that the URL Rewrite and Application Request Routing modules are properly installed and configured.
References
| Title | Link |
|---|---|
| URL Rewrite Module | https://www.iis.net/downloads/microsoft/url-rewrite |
| Application Request Routing Module | https://www.iis.net/downloads/microsoft/application-request-routing |