Running Rust executable app in IIS

This is more or less the same for Go and the like where the binary(“exe”) can listen to on a given port. That and I want to thank Sutean for his post similar to well this one; however, I wanted to dig in a little further into the application pool explanation and provide some additional insight for those that only have to setup IIS every blue moon having my own documented. Further I’m going to be extremely basic so something that seems straight forward will be included. I also used Actix web for my server, but again this could be any framework where the executable can listen on a port.

Let’s create Rust App:

Then “cargo build — release”

Yes, there are several ways to make something basic I have more complex examples of app config if you have questions feel free to ask. Also be careful with debug logs as I’ve included above this can eat up space quick. So we have our exe let’s move on to the server.

So on the server I copied my little executable from our release build above to a folder in the directory pictured below. We will go into the web.config file below but for now this could just be an empty web.config file.

Image for post
Image for post

For the server setup we first thing we need is the ASP.net core hosting addon found here. Once that is installed then we can configure the web.config file for our needs. Before we do this know the ways of the past have changed from using url rewrite to httpplatformhandler, and now currently asp.net core hosting. The later comes with two variants of hosting models. In and out of process just know that out of process comes with some overhead. You can read about the differences in detail here. Also all the configuration params can seen here though you need to scroll to the “Attributes of the aspNetCore element”.

Let’s get started first create the site:

Image for post
Image for post

So the physical path is where we saved the binary and config file. Next make the changes to the file as such

Alright now let’s look at the application pool advanced settings

Image for post
Image for post

I wanted to make mention of a few areas and point out some things.

First in order for the app to actually work we need to change the .net CLR version to “no managed code”.

If you are processing your requests pretty heavily you might encounter several 503 errors you can raise that via the queue length.

The start mode doesn’t really matter in our simple case but if you are caching data on the server you prob want it always running.

The maximum number of workers is a grey area. Actix will use the max amount of workers available. I would assume if the code is unmanaged this setting would have no effect and actix would use the max available if anyone can comment on this I’d appreciate the clarity.

Look over your recycle settings to fit your needs.

Also, take a look at the settings under “Advanced Settings” for “Physical Path Credentials”. Set this appropriately or the app may stop working after passwords are changed or enforced to change by policy. You can see the config in windows/system32/inetsrv/config/applicationHost.

Alright, well everything is setup and configured by this point because we should have grabbed the port from the environment var so we should be able to just browse localhost/test and see our string.

Image for post
Image for post

Huzzah! Yes, it’s IE :( but it’s a simple dev box

We added logging though let’s check where that is. The logging in the ISS window has no control over the actual log by the stdout we are generating from actix middleware. So you can change the below to fit your preference just know that isn’t the only step for getting logging out.

Image for post
Image for post

You will want to create a logs folder and then change the security settings on it to give the created application pool access via IIS AppPool\<your app pool name here> . Just make sure your are in the right location.

Image for post
Image for post

Then after you check names it should resolve to the app pool name then give it write permissions. Once this is done you might want to restart if it was already started and then see the logs fill stdout files.

Image for post
Image for post

Aside, if you fire up your server and think everything is configured and get status code 500 with no errors or logs (provided you are logging) chances are your web.config has a typo or things like the param being case sensitive. You can verify this by clicking on the config and ensure that it opens.

Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store