How to Use ENGINYRING’s NGINX with PageSpeed Docker Image on Your VPS
ENGINYRING is proud to offer its optimized NGINX with PageSpeed Docker image, designed for enhancing website performance. This tutorial will guide you through deploying and using this image on your Virtual Private Server (VPS). Please note that Docker requires a KVM-based VPS; LXC-based servers are incompatible.
Why Choose ENGINYRING’s NGINX with PageSpeed?
PageSpeed, integrated into NGINX, automatically optimizes web content, reducing load times and improving user experience. ENGINYRING’s Docker image provides:
- Pre-configured NGINX 1.27.3 with PageSpeed module.
- Optimized for fast deployment.
- Lightweight and secure.
Benefits of Using PageSpeed
- Improved Page Load Times: Minifies CSS, JavaScript, and HTML, reducing page size.
- Better SEO Rankings: Faster websites rank higher in search engine results.
- Enhanced User Experience: Provides a smoother and more responsive browsing experience.
Prerequisites
- A KVM-based VPS with Docker installed. You can explore ENGINYRING’s VPS plans.
- Basic knowledge of Linux command line.
- Sudo or root access.
Step 1: Pull the Docker Image
Log in to your server and pull the Docker image:
docker pull enginyring/nginx-pagespeed:bookworm
This command downloads the latest version of ENGINYRING’s optimized Docker image.
Step 2: Run the Docker Container
Run the container with the following command:
docker run -d \
--name nginx-pagespeed \
-p 80:80 \
-p 443:443 \
enginyring/nginx-pagespeed:bookworm
This will bind your VPS’s ports 80 and 443 to the container, making your optimized web server accessible.
Customizing the Run Command
You can add environment variables or mount volumes for more control. For example:
docker run -d \
--name nginx-pagespeed \
-p 80:80 \
-p 443:443 \
-v /path/to/your/config:/etc/nginx/conf.d \
enginyring/nginx-pagespeed:bookworm
Step 3: Verify PageSpeed Module
To confirm PageSpeed is working, visit your site and inspect the response headers. Use the following command to check headers:
curl -I http://your-server-ip
You should see the X-Page-Speed
header:
X-Page-Speed: 1.14.36.1-0
If this header is present, the PageSpeed module is active and optimizing your content.
Step 4: Configure NGINX
To customize your NGINX setup, edit the configuration files inside the container. Access the container shell:
docker exec -it nginx-pagespeed /bin/bash
Navigate to the configuration directory:
cd /etc/nginx
Edit the configuration files using a text editor like nano
or vi
:
nano /etc/nginx/conf.d/default.conf
After making changes, reload NGINX:
nginx -s reload
Common Configuration Adjustments
- Enabling Cache: Adjust
pagespeed
cache settings to suit your website’s needs. - Custom Compression Levels: Fine-tune gzip settings for optimal performance.
Step 5: Enable HTTPS
For a secure setup, use Let’s Encrypt to enable HTTPS. You can integrate a certificate by:
- Installing Certbot:
apt update && apt install certbot
- Running Certbot inside the container:
certbot certonly --webroot -w /usr/share/nginx/html -d yourdomain.com
- Updating your NGINX configuration to use the certificate. Example:
server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
}
Restart NGINX to apply the changes:
nginx -s reload
Step 6: Monitor and Optimize
Monitoring Performance
Use tools like htop
or docker stats
to monitor resource usage:
docker stats nginx-pagespeed
Analyzing Logs
Review NGINX logs to identify performance bottlenecks:
docker logs nginx-pagespeed
Fine-Tuning PageSpeed
Experiment with different PageSpeed filters to maximize performance. Example filters include:
extend_cache
for better caching.collapse_whitespace
to reduce HTML size.
Troubleshooting
Common Issues
- Ports Already in Use
Ensure no other services are occupying ports 80 or 443:
sudo lsof -i :80
sudo lsof -i :443
- Docker Permission Issues
Run Docker commands withsudo
or add your user to thedocker
group:
sudo usermod -aG docker yourusername
- Configuration Errors
Check NGINX logs for errors:
docker logs nginx-pagespeed
- LXC Compatibility
Remember, LXC-based servers cannot run Docker. Switch to a KVM-based VPS if needed.
Conclusion
Deploying ENGINYRING’s NGINX with PageSpeed Docker image is straightforward and delivers significant performance improvements. Start optimizing your websites today with ENGINYRING VPS plans.