NetrunHome

Sites and apps

How to deploy a Rust app: Axum, Actix or Rocket

· 5 min read

In short

To deploy a Rust app you need a machine that compiles the sources and keeps the binary running. The simplest route is to upload the project folder to Netrun: the platform picks up Cargo.toml, builds the project and gives you a public HTTPS link. All that is asked of your code is to read the port from the PORT environment variable and bind to 0.0.0.0. Expect the first build to take longer than it would for a Python or Node.js project, because the compiler builds every dependency from scratch; later builds are faster.

The usual path to Rust hosting looks like this: rent a server, install the toolchain, build the project, put nginx in front of it, get a certificate, and work out how to restart the process after a crash or a reboot. The language is not the hard part. Rust compiles into a single executable file. Everything around that file is infrastructure work, and normally it lands on you.

Netrun removes that layer: you upload the source code, the platform sees Cargo.toml, builds the project and gives you a public link with HTTPS (a secure connection, the padlock in the browser). No server, no nginx, no manual certificate. Below is what to fix in your code before publishing, and what to expect from the first build, because in Rust it takes noticeably longer than in other languages.

  1. Keep Cargo.toml in the project root#

    Cargo.toml lists your dependencies and tells the platform that this is a Rust project. We build from it: the toolchain and the crates are pulled in on our side, so you do not need Rust installed anywhere. Zip the contents of the project folder so Cargo.toml ends up at the top level of the archive rather than inside an extra wrapper folder.

  2. Leave the target folder out of the archive#

    The target folder is the result of your local build. It is very large and it gets recreated on our side anyway, so there is no reason to upload it: without it the archive is many times smaller. A binary you compiled on your own machine is not needed either, because we build from source.

  3. Read the port from the environment and bind to 0.0.0.0#

    A web app has to listen on the port the platform sets in the PORT environment variable, not on a number hard-coded in the source. In Rust that is std::env::var("PORT"), and the bind address has to be 0.0.0.0 rather than 127.0.0.1, otherwise the app only answers inside the container and the link stays blank. In Axum this is the address in TcpListener::bind, in Actix Web it is the argument to bind, and in Rocket it is easier to build the config in code from PORT than to keep it in Rocket.toml.

  4. Move keys and tokens into secrets#

    Read API keys, bot tokens and database connection strings from environment variables with std::env::var instead of hard-coding them as constants. Netrun asks for these values during project setup and passes them in encrypted, so they never sit in the archive or in your GitHub repository. There is no need to include a .env file.

  5. Upload the code and wait out the first build#

    Bring the project in as a ZIP archive or import a GitHub repository, private ones included. Now the honest warning: the first build of a Rust project is the slowest of any supported language, because the compiler builds every dependency from scratch in release mode. That is expected rather than a failure, and the status and live logs in your dashboard show that the build is moving.

  6. Grab the link and update the code from your dashboard#

    When the build finishes you get a public HTTPS address you can open and send to anyone. A new version goes out the same way: upload a fresh archive or update the project from GitHub, and the link stays the same. Repeat builds are usually faster than the first one.

Your Rust app is online at an ordinary link, with no rented server, no nginx and no manual certificate. On the free plan you get one project: a web app sleeps while nobody uses it and wakes up when the link is opened, while a background service without a web address runs for three days and is then switched off, with your code, settings and secrets kept. If the app has to answer around the clock with no wake-up delay, the Pro plan is a better fit, and current prices and limits are shown in your dashboard. Try Netrun.

Common questions

Why does the first Rust build take so long?

The compiler builds not only your code but every dependency from scratch, in release mode with optimisations, which makes it the slowest build of any supported language. That is expected and does not mean something broke: you can watch the progress in the logs in your dashboard. Later builds are usually much faster.

Do I have to compile the binary myself and upload the file?

No, upload the sources: Cargo.toml, the src folder and the rest of the project files. The build happens on our side, so you do not need Rust or a toolchain installed locally. A binary compiled on macOS or Windows would not run on the server anyway.

Do Axum, Actix Web and Rocket work?

Yes, the framework can be anything: the project is recognised from Cargo.toml, not from the name of the library. The requirement is the same for all of them, which is to bind to 0.0.0.0 and to the port from the PORT environment variable. With Rocket the easiest way is to build the configuration in code instead of using Rocket.toml.

What if the project has several binaries?

Point to the main one with default-run in Cargo.toml so it is unambiguous what should start. The same goes for a project made of several packages: arrange it so there is a single entry point. Otherwise the build may pick a binary other than the one you meant.

The build succeeded but the link does not open. What should I check?

Start with the port and the address: the app has to listen on 0.0.0.0 and on the port from the PORT variable, not on 127.0.0.1 and a number from the source. The second common cause is the app crashing right after startup, for example because a key is missing or a database is unreachable. Both show up in the logs in your dashboard, with the error text and the moment the process stopped.

Which languages and technologies are supported?

Python, Node.js, Go, Rust, Ruby, PHP, Java, .NET, Deno, Bun, Elixir, static sites and bash scripts. You can bring your own Dockerfile or docker-compose, but more often the stack is detected from your code automatically.

Do I need my own server or VPS?

No. Netrun deploys your project on its own servers. There is no VPS to rent, no systemd or nginx to configure and no certificates to renew — all of that runs for you.

Do I need to know how to work with Docker?

No. Netrun detects which language your project uses and builds it for you. If you already have a Dockerfile or docker-compose, we support them, but you do not need to write them specially.

Why does my website sometimes sleep?

On the free plan, websites sleep after being idle and wake up in a couple of seconds on the first request. On the Pro plan your project runs without sleeping.

Get your own project online

Upload your code, answer a couple of questions and get a working link. There is a free plan

Try Netrun
All blog articles