How to Deploy an Actix Web App on a VPS

deploy actix web on ubuntu vps

If you’ve built a web service with Actix, the next step is getting it online. The good news is that deploying to a VPS is simple once you know the workflow. This guide walks you through everything from building your app to serving it behind Nginx with optional HTTPS.

The steps below assume you’re using Ubuntu, but the process is almost the same for any Linux distribution.

1. Update Your Server

Start by making sure your VPS is up to date.

sudo apt update && sudo apt upgrade -y

It’s a quick step, but it prevents odd issues later.

2. Install Rust (if you plan to build on the server)

You can compile the app directly on the VPS or build it locally and upload the binary. If you want to build on the server:

curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env

If you’re building locally, skip ahead and upload your compiled binary later.

3. Build Your Actix App in Release Mode

Release mode produces an optimized executable.

cargo build --release

You’ll find the compiled binary here:

target/release/your_app_name

4. Create a Dedicated User for the App

This helps keep things clean and secure.

sudo useradd -r -m -d /var/www/actix appuser

Copy the binary and any configuration files:

sudo cp target/release/your_app_name /var/www/actix/
sudo chown appuser:appuser /var/www/actix/your_app_name

5. Run the App with systemd

Systemd makes sure your app starts on boot and restarts if it crashes.

Create a service file:

sudo nano /etc/systemd/system/actix.service

Add this:

[Unit]
Description=Actix Web App
After=network.target

[Service]
User=appuser
WorkingDirectory=/var/www/actix
ExecStart=/var/www/actix/your_app_name
Restart=always
Environment=RUST_LOG=info

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable actix
sudo systemctl start actix
sudo systemctl status actix

At this point your app should be running internally, often on port 8080 or whatever you configured.

6. Set Up Nginx as a Reverse Proxy

Nginx forwards web traffic to your Actix app. Install it:

sudo apt install nginx -y

Create a server block:

sudo nano /etc/nginx/sites-available/actix

Add:

server {
    listen 80;
    server_name your_domain_or_ip;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Enable it and reload Nginx:

sudo ln -s /etc/nginx/sites-available/actix /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Now you can access your app through your server’s IP or domain.

7. Add HTTPS with Certbot (optional but recommended)

If you have a domain, securing it is easy.

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d your_domain

Certbot updates your Nginx config and sets up automatic renewal.

8. Open Firewall Ports

If you’re using UFW:

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable

At this point your server should be reachable on ports 80 and 443.

Leave a Reply

Your email address will not be published. Required fields are marked *