Building on this article from gjcampbell about running Azure Functions on IIS, I set about trying to do this myself. I ran into enough issues based on the information provided that I decided to write my own article.
This work was based on standing up a plain Windows Server 20H2 VM.
- Download the "Azure Functions Host" binaries from Github. ( I downloaded 4.2.1 )
- Download the Dotnet Core Hosting package ( I downloaded dotnet-hosting-6.0.3-win.exe)
- Install IIS on Windows Server.
- I didn't know what I needed so I installed everything
Install-WindowsFeature -Name Web-Server -IncludeAllSubFeature -IncludeManagementTools
- Unzip the Azure Functions file somewhere. I chose C:\inetpub\AzureFunctions
- I removed the default IIS site and created a new one at C:\inetpub\wwwroot
- I made this the web.config at C:\inetpub\wwwroot\web.config .
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<environmentVariables>
<environmentVariable name="AzureWebJobsStorage" value="UseDevelopmentStorage=true" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
- Finally, You need to grant the IIS_USRS Read and Execute access to the C:\inetpub\AzureFunctions.
- I was doing this on Windows Server Core and was having trouble with my icacls commandline-fu I was in a rush so I just gave everyone full access
icacls C:\inetpub\AzureFunctionHost /grant everyone:F /t
- After updating the web.config, restart IIS.
iisreset
- I had issues with this and often had to run it twice.
- Checking the Event Log for issues
Get-EventLog -LogName application |select -first 10 |ft -AutoSize -Wrap
- Putting it all together and testing the webpage
iisreset; curl localhost ; Get-EventLog -LogName application |select -first 10 |ft -AutoSize -Wrap
-
See previous comment about having to run iisreset twice; i often ran this twice as well because of that. Probably something silly on my install
-
After getting this all set and before I had fixed the permissions I was getting a 503 error. This turned out to be because the IIS account couldn't access the Azure Functions files. I created a user; added it to the IIS_USRS group and then tested it's access with the following:
net user iis_test Super1_Secure@_Password- /Add
runas /user:iis_test cmd.exe
REM # This Will open a new CMD window
REM # In that window
whoami
REM # this should return IIS_TEST
C:\inetpub\AzureFunctionHost\4.2.1\bit\Microsoft.Azure.WebJobs.Script.WebHost.exe
REM # if this runs you should be good to go. If it doesn't run you need to resolve whatever errors it throws. If the error is file not found refer to the above icacls command where I gave "everyone" full control of the directory.
Hey, I'm trying to get this up and running myself. I'm like 95% of the way there. I can hit the functions splash page at the root path
http://example.com
, but I get a 404 for any other routes (such ashttp://example.com/api/test
) Have you run into this at all?