Nginx
Nginx is a high-performance web server, reverse proxy, and load balancer known for its speed, scalability, and reliability. It is widely used to serve static content, handle HTTP requests, and manage traffic for web applications.
Serving static filesโ
This guide walks you through deploying a simple static website with Nginx on lttle.cloud, from basic setup to adding flash mode for cost-efficient serverless hosting.
To reduce compute and memory usage, there are certain Nginx optimizations that we recommend
- Pre-compressing static files. Our example uses gzip compression with the
gzip_staticmodule. Or if you use Nginx Plus, you can use thebrotli_staticmodule for better compression ratios. - Using the
sendfileandsendfile_max_chunkdirectives to optimize file transfers - Using the
tcp_nopushdirective to improve network performance - Allocating minimal resources since Nginx is lightweight
If you want to skip the explanations, you can find the complete final example in our GitHub Samples ยป Nginx ยป Custom Nginx Server with Dockerfile.
Creating the static siteโ
Create a file named index.html with any content you like, for example:
echo "Hello from Nginx via lttle.cloud! (custom dockerfile)" > index.html
Or you can use any static site generator or framework to create a more complex static site.
Nginx configurationโ
Create a file named nginx.conf with the following content:
server {
listen 80;
server_name _;
# Use linux sendfile syscall to speed up file transfers
# and reduce mem & cpu usage
sendfile on;
sendfile_max_chunk 1m;
# Enable tcp_nopush to optimize network performance
tcp_nopush on;
root /usr/share/nginx/html/;
location / {
# Try to serve pre-compressed file first, then fall back to regular file
# to reduce mem & cpu usage
gzip_static on;
gzip_comp_level 69;
}
}
Docker imageโ
Create a file named Dockerfile with the following content and make sure to pre-compress all static files with gzip:
FROM nginx:latest
# Our custom nginx config file
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
# Our static website
COPY ./index.html /usr/share/nginx/html/index.html
# Compress all build files with gzip
# But keep original files as well
RUN find . -type f -exec gzip -9 -k \{\} \;
Deploymentโ
Now that everything is setup, we can deploy our app, check the deployment and then remove it.
Deployment configurationโ
Create a file named nginx-custom-dockerfile.lttle.yaml with the following content:
app:
name: nginx-custom-dockerfile
namespace: samples
build:
docker:
dockerfile: dockerfile
context: .
resources:
# Nginx is very lightweight, so we can use minimal resources
# Make sure to allocate enough cpu and memory for your static site(s) needs
cpu: 1
memory: 64
expose:
# We expose a public HTTPS endpoint that
# proxies to the Nginx server on port 80
public:
# When there are no more active connections to our service
# It will be safe to snapshot & sleep our machine
connection-tracking: connection-aware
port: 80
external:
protocol: https
mode:
flash:
strategy:
# We snapshot and save the state of the container
# After it has listened on port 80
listen-on-port: 80
Deployingโ
To deploy the application, run the following command in the directory where you created the nginx.lttle.yaml file:
lttle deploy nginx-custom-dockerfile.lttle.yaml
Building and pushing image for samples/nginx-custom-dockerfile
Built image eu.registry.lttle.cloud/your-tenant/f6a1db28-2d0a-4a09-bf0e-915970223be6:latest
Pushing image eu.registry.lttle.cloud/your-tenant/f6a1db28-2d0a-4a09-bf0e-915970223be6:latest
Pushed image for samples/nginx-custom-dockerfile โ eu.registry.lttle.cloud/your-tenant/f6a1db28-2d0a-4a09-bf0e-915970223be6:latest
Successfully deployed app: samples/nginx-custom-dockerfile
Checking the deploymentโ
After the deployment is complete, you can check the status of your application by running:
lttle app get --ns samples nginx-custom-dockerfile
name: nginx-custom-dockerfile
namespace: samples
mode: flash
snapshot strategy: listen on port 80
suspend timeout: 10s
image: eu.registry.lttle.cloud/your-tenant/f6a1db28-2d0a-4a09-bf0e-915970223be6:latest
cpus: 1
memory: 64 MiB
services: public: https://nginx-custom-dockerfile--samples--public--your-tenant.eu.lttle.host โ :80
If you want to see it live, you can
- Deploy and change
your-tenantto your actual tenant name and then click the link in theservicessection above - Or you can visit our deployment of this sample at: https://nginx-custom-dockerfile--samples--public--aifrim.eu.lttle.host/
Checking the logsโ
You can view the logs of your application by running:
lttle app logs --ns samples nginx-custom-dockerfile -f
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/\
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
/docker-entrypoint.sh: Ignoring /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh.gz
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Ignoring /docker-entrypoint.d/15-local-resolvers.envsh.gz
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Ignoring /docker-entrypoint.d/20-envsubst-on-templates.sh.gz
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Ignoring /docker-entrypoint.d/30-tune-worker-processes.sh.gz
/docker-entrypoint.sh: Configuration complete; ready for start up
2025/10/11 17:38:32 [notice] 1#1: using the "epoll" event method
2025/10/11 17:38:32 [notice] 1#1: nginx/1.29.2
2025/10/11 17:38:32 [notice] 1#1: built by gcc 14.2.0 (Debian 14.2.0-19)
2025/10/11 17:38:32 [notice] 1#1: OS: Linux 6.1.0+
2025/10/11 17:38:32 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1024:4096
2025/10/11 17:38:32 [notice] 1#1: start worker processes
2025/10/11 17:38:32 [notice] 1#1: start worker process 23
Removing the deploymentโ
lttle app delete --ns samples nginx-custom-dockerfile -y
App 'nginx-custom-dockerfile' has been deleted.
Recommendationsโ
Do not use Nginx for:
- Reverse proxying
- Load balancing
- Rate limiting
Instead, use services provided by lttle.cloud for these functionalities. They have been optimized for serverless environments and will provide better performance and reliability.