0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
JPPINTO
  • Home
  • Blog
  • Certifications
  • About
  • Contact
  • Shop
  • Gallery
  • Current Setup
Contact

Search

July 3, 2026 / Linux, Servers, Ubuntu

Install and Tune Nginx on Ubuntu for Web Hosting

Tags: linux, nginx, server setup, ubuntu, web server
Featured image for Install and Tune Nginx on Ubuntu for Web Hosting

Nginx is a fast web server and reverse proxy that is commonly used for WordPress, PHP apps, static sites, APIs, and load-balanced web services.

This guide shows a clean Nginx install flow for Ubuntu, including service enablement, basic tuning, configuration backup, validation, and restart.

The examples use generic paths and values. Adjust them for your own server.

What the Script Does

The deployment script this article is based on does four main things:

  • Installs Nginx with apt.
  • Enables the nginx service.
  • Backs up /etc/nginx/nginx.conf.
  • Updates common settings such as worker_connections, keepalive_timeout, and client_max_body_size.
  • Runs nginx -t before restarting the service.

Install Nginx

Run the install commands as root or with sudo:

sudo apt update
sudo apt install -y nginx
sudo systemctl enable nginx

Start or restart Nginx:

sudo systemctl restart nginx
sudo systemctl is-active --quiet nginx

If the last command returns no output, the service is active. You can also check status with:

sudo systemctl status nginx

Back Up the Nginx Config

Before editing Nginx, save a timestamped backup:

sudo mkdir -p /opt/server-backups/nginx
timestamp="$(date +%Y%m%d%H%M%S)"
sudo cp /etc/nginx/nginx.conf "/opt/server-backups/nginx/nginx.conf.before.${timestamp}.bak"

Backups are useful because a bad Nginx edit can stop the web server from reloading.

Tune Common Nginx Settings

This example sets:

  • worker_connections to 4096.
  • keepalive_timeout to 65.
  • client_max_body_size to 64M.

You can apply those settings with:

sudo sed -i "s/worker_connections .*/worker_connections 4096;/" /etc/nginx/nginx.conf

if sudo grep -q "keepalive_timeout" /etc/nginx/nginx.conf; then
    sudo sed -i "s/keepalive_timeout .*/keepalive_timeout 65;/" /etc/nginx/nginx.conf
else
    sudo sed -i "/http {/a \    keepalive_timeout 65;" /etc/nginx/nginx.conf
fi

if sudo grep -q "client_max_body_size" /etc/nginx/nginx.conf; then
    sudo sed -i "s/client_max_body_size .*/client_max_body_size 64M;/" /etc/nginx/nginx.conf
else
    sudo sed -i "/http {/a \    client_max_body_size 64M;" /etc/nginx/nginx.conf
fi

client_max_body_size is especially important for sites that accept uploads. If it is too small, uploads may fail with 413 Request Entity Too Large.

Validate Before Restarting

Always test the config before restarting:

sudo nginx -t

If the syntax test succeeds, restart Nginx:

sudo systemctl restart nginx
sudo systemctl is-active --quiet nginx

Then save an after-change backup:

sudo cp /etc/nginx/nginx.conf "/opt/server-backups/nginx/nginx.conf.after.${timestamp}.bak"

Troubleshooting

If Nginx fails to start, check the config test:

sudo nginx -t

Check the service logs:

sudo journalctl -u nginx -xe

Restore the backup if needed:

sudo cp /opt/server-backups/nginx/nginx.conf.before.YYYYMMDDHHMMSS.bak /etc/nginx/nginx.conf
sudo nginx -t
sudo systemctl restart nginx

Quick Reference

sudo apt update
sudo apt install -y nginx
sudo systemctl enable nginx
sudo nginx -t
sudo systemctl restart nginx

Nginx changes should always follow the same rhythm: back up, edit, validate, restart, and verify.

Post Views: 26
<- Fix Windows Line Endings and Make Shell Scripts Executable in Linux
Install PHP-FPM and Common PHP Extensions on Ubuntu ->

Categories

  • Active Directory (5)
  • AI (2)
  • Amazon Cloud Services (1)
  • Blazor (1)
  • C# (C-Sharp) (3)
  • CI/CD Pipelines (1)
  • Containers (4)
  • Deployment (2)
  • Development (4)
  • Docker (3)
  • General (5)
  • IIS 6.0 (4)
  • IIS 7.0 (10)
  • IIS 8.0 (1)
  • Infrastructure as Code (IaC) (1)
  • Kubernetes (3)
  • Linux (8)
  • Microsoft 365 (2)
  • MySQL (1)
  • Office 2010 (1)
  • PHP (1)
  • PowerShell (7)
  • Productivity (1)
  • Servers (8)
  • SharePoint 2007 (8)
  • SharePoint 2010 (19)
  • SharePoint 2013 (2)
  • SharePoint Online (1)
  • SMTP (4)
  • SQL Server 2008 (1)
  • SQL Server 2008 R2 (1)
  • SQL Server 2012 (2)
  • SQL Server 2019 (1)
  • Ubuntu (8)
  • Uncategorized (1)
  • URL Rewrite (2)
  • Visual Studio 2019 (1)
  • Visual Studio Code (1)
  • Windows 10 (5)
  • Windows 2003 (9)
  • Windows 2008 (18)
  • Windows 2012 (6)
  • Windows 7 (3)
  • Windows Firewall (1)
  • Windows Vista (1)
  • WordPress (3)
  • WP-CLI (3)

Recent Posts

  • Create an Nginx Default Catch-All Site on Ubuntu
  • Install and Configure Redis on Ubuntu for Local Object Cache
  • Install and Configure MySQL on Ubuntu for WordPress
  • Install PHP-FPM and Common PHP Extensions on Ubuntu
  • Install and Tune Nginx on Ubuntu for Web Hosting

Advertisement

Tags

ai coding agents bash developer workflow dev to production exe permissions externalize blob externalize sharepoint data filezilla server firewall rules filazilla full installation http redirect https https redirect IIS iis7 iis 7 installation IIS installation index server configuration installing cumulative updates linux load balance central administration microsoft 365 nginx nlb powerpoint powershell redirect http to https server setup sharepoint 2010 cumulative updates sharepoint 2010 farm build sharepoint 2010 farm configuration sharepoint 2010 farm installation sharepoint data externalization SMTP storagepoint ubuntu web server windows Windows 7 windows firewall configuration windows server 2008 wlbs wordpress wp-cli x86
© 2026 JPPinto.com. All rights reserved.