I Set Up My Own Web Server and Here's What I Learned About Nginx


- Premium Results
- Publish articles on SitePoint
- Daily curated jobs
- Learning Paths
- Discounts to dev tools
7 Day Free Trial. Cancel Anytime.
I Set Up My Own Web Server and Here's What I Learned About Nginx
So I wanted to run my own website on a VPS. A VPS is basically a computer you rent in some data center. You get a Linux terminal and you figure it out.
I kept seeing the word "nginx" everywhere. I had no idea what it was. My friend said "it's a web server" but that still didn't really help me. So I dug in and spent a weekend learning it. Here's what I found out.
What Even Is Nginx?
Nginx (you say it "engine-x") is software that runs on your server. It listens for people visiting your website. When someone types your URL into their browser, nginx is the thing that answers and sends back the page.
That's the simple version. But nginx does a lot more than that. It can also act as a middleman between your visitors and your actual app. It can compress files before sending them so pages load faster. It handles HTTPS. It even blocks bad traffic if you set it up right.
Big companies like Netflix use it. If it can handle Netflix traffic, it can definitely handle your blog.
Getting a Server First
Before you install nginx, you need a server. I got a VPS. The cheapest ones start at like 15 dollars a month or less. You want at least 1GB of RAM and a couple of CPU cores if you expect real traffic.
Go with Ubuntu. It's the easiest Linux for beginners and most tutorials use it.
Installing Nginx
This part is actually really easy. Two commands:
sudo apt update
sudo apt install nginx
Done. Nginx is installed. You can check if it's running:
sudo systemctl status nginx
If you see "active (running)" in green, you're good. You can open your server's IP address in a browser and you'll see the default nginx welcome page.
Other commands you'll use all the time:
sudo systemctl restart nginx # restart it
sudo systemctl reload nginx # reload config without dropping connections
sudo systemctl enable nginx # make it start automatically when server reboots
The Config File
Nginx lives in /etc/nginx/. The main config file is at /etc/nginx/nginx.conf. This is where you control everything.
Here's a solid base config. You can copy this and it works well for most sites:
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options DENY;
server_tokens off;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript;
include /etc/nginx/sites-enabled/*;
}
The gzip on line is important. Gzip compresses files before nginx sends them. Pages can load 2 to 5 times faster just from that one setting.
The server_tokens off line hides which version of nginx you're running. Less info for hackers.
Setting Up Your Domain
Every website you host needs its own config file. You put these in /etc/nginx/sites-available/.
Create a file for your domain:
sudo touch /etc/nginx/sites-available/yourdomain.com
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
The second command creates a symlink. That's how nginx knows to actually use this config.
Now open the file and add this. Replace yourdomain.com with your actual domain:
server {
listen 80;
server_name yourdomain.com;
return 301 https://yourdomain.com$request_uri;
}
server {
listen 443 ssl http2;
server_name yourdomain.com;
ssl_certificate /etc/ssl/certificate.crt;
ssl_certificate_key /etc/ssl/private.key;
root /var/www/yourdomain.com;
index index.php index.html;
location ~* \.(css|js|jpg|png|gif|svg|webp|woff2)$ {
expires 30d;
add_header Cache-Control "public";
}
client_max_body_size 10M;
}
The first block forces everyone onto HTTPS. The second block is your actual site. The expires 30d part tells browsers to cache images and CSS for 30 days so repeat visitors load your site faster.
After editing any config, test it first:
sudo nginx -t
If it says "test is successful" you're fine. Then reload:
sudo systemctl reload nginx
File Uploads and the 413 Error
The default nginx upload limit is 1MB. If someone tries to upload a photo and gets a "413 Request Entity Too Large" error, that's why.
The client_max_body_size line in your config controls this. Set it based on what your site needs:
- Simple contact forms: 5MB is plenty
- Blog with image uploads: 10MB to 64MB
- E-commerce site: 50MB to 100MB
- Video platform: 500MB to 2GB
You can also set different limits for different parts of your site:
location /upload {
client_max_body_size 100M;
}
That's smarter than raising the global limit and leaving yourself open to people uploading huge files everywhere.
SSL Certificates
HTTPS is not optional anymore. Browsers show scary warnings for HTTP sites. Google also ranks HTTPS sites higher.
Get a free SSL certificate from Let's Encrypt. It's easy to set up and auto-renews.
Put the certificate files in /etc/ssl/ and point your nginx config at them like I showed above. That's it.
Why This All Matters for Performance
When I configured nginx properly on my VPS, pages loaded noticeably faster. Here's what made the biggest difference:
Gzip compression cut my CSS and JavaScript file sizes by more than half. HTTP/2 (enabled with http2 in the listen directive) lets browsers load multiple files at the same time over one connection. Browser caching meant returning visitors didn't have to download images they already had. Together these things made a real difference.
You can read more about performance tuning and get the full config files in the original complete nginx guide which goes deeper on every step.
The Robots.txt and Sitemap Thing
Two more files you need for SEO. Put a robots.txt at the root of your site:
User-agent: *
Disallow: /private/
Allow: /
Sitemap: https://yourdomain.com/sitemap.xml
This tells search engine bots what pages to crawl and where your sitemap is.
Your sitemap.xml lists every page on your site with a priority. Your homepage gets 1.00. Regular pages get 0.8. Blog posts get 0.6. This helps Google understand your site structure.
Nginx vs Apache: Which Should You Pick?
People argue about this a lot. The short answer: use nginx.
Apache has been around longer and more shared hosting uses it. But nginx uses way less memory and handles more connections at the same time. If you're running your own VPS, nginx is the better choice for almost every situation.
The SitePoint comparison of WebGPU vs WebGL for browser inference shows how picking the right architecture (not just the familiar one) can give you 3 to 8 times better performance. Same idea applies here. Nginx was built for the way the web works now. Apache was built for an older model.
If you want to go deeper on the actual architecture of how web servers handle requests and why it matters, the SitePoint guide to local-first AI actually has a great section on GPU compute and event-driven architecture that explains the same concepts nginx uses to handle thousands of connections at once.
Quick Checklist Before You Go Live
Before you point your domain at your server, go through this:
- Nginx installed and running.
- Config tested with
sudo nginx -t. - SSL certificate installed and HTTP redirects to HTTPS.
server_tokens offin your config.- Gzip compression enabled.
- Browser caching set for static files.
client_max_body_sizeset to something that makes sense for your site.- Robots.txt and sitemap.xml created and linked.
That's really it. Nginx sounds intimidating but once you understand the config file structure it's pretty logical. The config is just text files. You edit them, test them, reload nginx, and your changes are live.
I spent way too long being scared of this stuff. It's not that hard once you actually try it.