Skip to content

Instantly share code, notes, and snippets.

@renenw
Last active March 11, 2018 19:02
Show Gist options
  • Save renenw/c33e4a48ac1e58d4fc4485f02751e746 to your computer and use it in GitHub Desktop.
Save renenw/c33e4a48ac1e58d4fc4485f02751e746 to your computer and use it in GitHub Desktop.
How to serve static HTTP content using Windows 10
Serve Static Content Using IIS Yes, fair question. Why would anybody want to serve any web content from a Windows 10 machine? Well, despite the numerical dominance of iOS and Ubuntu in my home, our households photos are stored on a Windows machine.

For kicks, I built a picture frame that should access the photos stashed on the "upstairs" computer.

It turns out the Windows does not make this easy. Or, perhaps, my background meant I found it harder to do than I think it ought to be.

The Process

This is a three step process:

  1. Install IIS ("Internet information server")
  2. Configure the site
  3. Add a web.config file.

I didn't find any of these steps at all obvious.

Install IIS

Open the control panel and navigate to Programs and Features (Control Panel \ Programs \ Programs and Features):

alt control panel

Click on Turn Windows features on or off and, within the dialog that opens, find Internet Information Services:

alt installation options

You need to enable:

  1. Web Management Tools \ IIS Management Console
  2. Common HTTP Features \ Static Content
  3. Common HTTP Features \ HTTP Errors (not strictly required, but I found the diagnostics really helpful)

Configure IIS

start IIS Manager (I just searched for it in the Windows search menu), and edit the default site:

First, change the path so that it points at your pictures directory (right click the site, select advanced settings, and set the Physical Path

alt update the path

Then, right click the site and Edit Permissions. You need a user: IIS_IUSRS (and you will need to select Edit to make the change).

alt give iss permissions

Add a web.config file

In the root of your web site:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <system.webServer>
   <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />
     </customHeaders>Why
   </httpProtocol>
 </system.webServer>
</configuration>

And Test!

That should be that. Point your browser at a specific file at http://localhost and you should be good to go!

NB NB: I did not enable add the IIS configuration that allows directory browsing, so you will need to be specific about the files you are after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment