# HttpServer Configuration
The HttpServer type is responsible for serving HTTP requests. It acts as the TCP listener, accepting connections, and dispatching them to the worker threads which run your App logic.
##Worker Threads
By default, HttpServer starts a number of worker threads equal to the number of logical CPUs on the system. This provides optimal performance for most workloads because it maximizes CPU utilization without overwhelming the OS scheduler.
You can override this using the .workers() method:
HttpServer::new(|| App::new())
.workers(4) // Specifically use 4 workers
.bind("127.0.0.1:8080")?
.run()
.awaitReducing the number of workers is useful in resource-constrained environments (like small Docker containers) or when your application relies heavily on external services and is fully async, thus not needing a lot of CPU.
##Connection Backlog and Keep-Alive
Actix Web allows you to tweak low-level networking parameters:
- Keep-Alive: By default, Actix enables HTTP keep-alive. You can configure the duration or disable it via
.keep_alive(). - Client Timeout: You can configure how long the server should wait for a client to send a full request via
.client_request_timeout(). - Max Connections: Prevent DDoS attacks by limiting concurrent connections using
.max_connections().
use std::time::Duration;
use actix_web::http::KeepAlive;
HttpServer::new(|| App::new())
.keep_alive(KeepAlive::Timeout(Duration::from_secs(75)))
.client_request_timeout(Duration::from_secs(5))
.bind("127.0.0.1:8080")?
.run()
.await##TLS / HTTPS
While it is common to deploy Actix Web behind a reverse proxy (like Nginx, HAProxy, or Traefik) that handles SSL termination, you can run Actix Web directly with TLS using libraries like rustls or openssl.
Using rustls:
// Note: Requires the 'rustls' feature enabled on actix-web
// .bind_rustls("127.0.0.1:8443", rustls_config)The HttpServer is highly configurable, ensuring that Actix Web can be tuned for almost any deployment scenario.