Stop http.sys from listening on port 80 in Windows

2011-11-06
On Windows 7 there is a system service called http.sys that listens on port 80. That makes it impossible to run applications and services that haven't been integrated with this feature to also listen on port 80, like Apache HTTP Server or Nginx. Here is one way to solve that problem.

Background information

First of all, the way http.sys works on newer Windows versions is a very useful feature. The reason behind http.sys is to have a single system service that listens on the all-important port 80 and be a mediator to different applications and services in the system that might like to handle incoming requests on port 80 but for different urls. What an integrated Windows application does, is use a Windows API for registering its own urls and then have them directed to itself. At the same time, there can be other applications also getting incoming requests to port 80 but for different registered urls.

The problem

The problem is that some (many?) open source project that have been compiled for Windows, does not use this http.sys API. Therefore, when they start up and try to bind to port 80, they will fail since it is occupied by http.sys. And I have to admit that I have no idea how easy or hard it would be to patch such a project to make that call on Windows and get the tcp/ip network stack to work with it.

Examples of such projects are:

(Haven’t looked at how nodejs does it.)

The solution

Some solutions I’ve found suggests disabling http.sys, but that only works if you are sure you won’t have any use for Windows applications that do know about http.sys. I didn’t want to do that.

My suggested solution is instead to tell http.sys to bind to a specific ip-address, and then use any other ip-addresses on your system for Nginx (or whatever you are looking to install). It turns out this is possible via the netsh command line configuration tool in Windows (from version 7 anyway).

So, one way would be to add an extra ip address to your network configuration. But I chose instead to use the fact that every system nowadays has both an ipv4 and an ipv6 address. My solution is to bind http.sys to the ipv6 general address (named “::”) and thereby free up the local general ipv4 address (named “127.0.0.1”) for my Nginx server.

Telling http.sys to bind to the ipv6 general address is easy. Just run the follow command from a command prompt window as Administrator:

netsh http add iplisten ipaddress=::

It seems that the name “localhost” binds to the ipv6 address, actually “::1″, so from now on you can still get the http.sys applications and services via “http://localhost”. And if you install and run Nginx on port 80 it should start fine and be available at “http://127.0.0.1″. Or you could even edit your “C:\Windows\System32\drivers\etc\hosts” file and add the line:

127.0.0.1 local

Now having “localhost” for ipv6/http.sys and “local” for ipv4/Nginx.

 

13 Responses to “Stop http.sys from listening on port 80 in Windows”

  1. [...] 80 being bound to a system service. If you’re running this as a production server, refer to this solution. If it’s a development server, just use another port. Here’s how you do [...]

  2. Matt says:

    How do I undo “netsh http add iplisten ipaddress=::”? now when I type in ipconfig i get a lot of stuff I’ve never seen before. I don’t know if this was an issue before though, but on this machine I can’t access my router at 192.168.1.1, other machines on the network can.

    Thanks,

    Matt

    • Adrian says:

      I would like to second this: how do I undo this? I have a feeling that this is having some unwanted side-effects.

    • mikeplate says:

      Undoing should be easy. Just run the same command but with “add” replaced with “delete”:

      netsh http delete iplisten ipaddress=::

      This removes the setting and if there are no other iplisten settings, http.sys will go back to listening on all addresses (don’t know if a reboot is necessary after these changes). If you’ve done multiple “add”, you can check the list of iplisten-settings like so:

      netsh http show iplisten

  3. mike says:

    thanks! super helpful and saved me what i’m sure would have been a couple of hours. i’m not sure why this vodoo happened in the first place. do you think a recent install of SQL Server could have done changed something?

  4. Jose Gonzalez says:

    I have to say and I’m serious about this. Your solution is 100% helpful, but it’s not the solution only and that’s it!!!! Your viewpoint about why windows runs the http system service and how it works and the comment about some good opensource projects along with possible solutions make me feel there are still awesome techs around.

    Thank you very much!!!!!!

  5. David Pintos says:

    Very useful! I spent a lot of hours searching a good solution for it and I found it! Thanks!!!

  6. Steffen says:

    Thank you. This saved my day. After moving my development environment from good old XP to Win7 my XAMPP didn’t want to start the Apache server anymore. Strangely on similar Win7 Webserver Apache runs as a service and probably starts before the http.sys because I don’t have that Problem there…

  7. […] Web Matrix 什么的。但是 in my case,我根本找不到这个服务。最后找到了这个,确实把 80 […]

  8. tufan says:

    thanx :D solution is 100% works

  9. […] Это перевод статьи на английском языке Stop http.sys from listening on port 80 in Windows […]

  10. Amir Banuazizi says:

    Thank you. After trying everything from trying to disable IIS to SQL to Windows remote services on Windows 2012 and port 80 still being in use, your simple solution fixed the problem. I wish XAMPP included your solution into their distribution.

  11. Mike says:

    Thanks so much, this helped resolved an issue some check scanning software that needed to run on port 80!

Leave a Reply

Twitter: @mikeplate