When you move from shared hosting to your own server, one of the first decisions is which web server to install. In practice, it is almost always Nginx or Apache. Both are free, open source, mature and used on huge numbers of sites. Neither is “the wrong choice”. They just think about the job a bit differently.
What a web server does
A web server listens for HTTP requests on ports 80 and 443, then decides what to send back. For a static file like an image or a CSS file, it reads the file from disk and returns it. For dynamic pages, it hands the request to something else, like PHP or a Node.js app, and passes the response back to the browser. It also handles HTTPS, redirects, compression, caching headers and so on.
Apache in a nutshell
Apache has been around longer and grew up in the era of shared hosting. Two things define it for beginners.
Modules
Apache’s features come as modules you switch on or off: mod_rewrite for URL rewriting, mod_ssl for HTTPS, mod_headers and many more. On Ubuntu you enable them with commands like:
sudo a2enmod rewrite
sudo systemctl restart apache2 .htaccess files
Apache lets you put a .htaccess file inside any folder to change settings for that folder, without touching the main config and without restarting the server. This is why shared hosting loves Apache: thousands of customers can each control their own redirects and rules.
RewriteEngine On
RewriteRule ^about$ about.php [L] The catch is performance. Apache has to check for .htaccess files in the folder path on every request. On a busy site that adds up, which is why on your own server it is better to put rules in the main virtual host config and turn .htaccess off if you do not need it.
Nginx in a nutshell
Nginx was built to handle lots of simultaneous connections efficiently. It uses an event-driven model, where a small number of worker processes handle many connections each, instead of dedicating a process or thread per connection. This keeps memory usage low and predictable under load.
Nginx has no .htaccess. All configuration lives in central files, usually under /etc/nginx/sites-available/, and you reload Nginx after changes. A basic site looks like this:
server {
listen 80;
server_name example.com;
root /var/www/example;
index index.html;
location / {
try_files $uri $uri/ =404;
}
} Once you get used to server and location blocks, it is very readable.
The PHP difference
This trips up a lot of beginners. Apache can run PHP inside itself using mod_php, so you install PHP and it just works. It can also talk to PHP-FPM, which is what many modern setups do.
Nginx cannot run PHP inside itself at all. It always passes PHP requests to PHP-FPM, a separate service. The config looks like this (the socket path depends on your PHP version):
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
} It is one extra service to manage, but it is a cleaner separation, and you can tune PHP independently of the web server.
Reverse proxying
If you build apps in Node.js, Python or Go, your app runs its own server on a port like 3000 or 8000. The web server sits in front and forwards requests to it. Both can do this, Apache with mod_proxy, Nginx with proxy_pass. Nginx is the more common pick for this job, and you will see it in most deployment guides and tutorials.
Quick comparison
- Configuration: Apache allows per-folder
.htaccess; Nginx keeps everything in central config files. - Static files and many connections: Nginx is known for being very efficient here.
- PHP: Apache can run it directly or via PHP-FPM; Nginx always uses PHP-FPM.
- Shared hosting: Apache (or Apache-compatible servers like LiteSpeed) is very common because of
.htaccess. - Reverse proxy for apps: both work, Nginx is the usual choice.
- Learning material: both have plenty. Apache’s docs are very thorough, Nginx’s are shorter but clear.
Using both together
Some setups put Nginx in front to handle HTTPS and static files, and pass dynamic requests to Apache behind it. This was popular for a while. For a beginner on a single small VPS, it is extra complexity you do not need. Pick one.
Handy commands for each
Test config before reloading, every single time:
# Nginx
sudo nginx -t
sudo systemctl reload nginx
# Apache
sudo apachectl configtest
sudo systemctl reload apache2 Logs are where you go when something breaks. On Ubuntu, Nginx logs live in /var/log/nginx/ and Apache logs in /var/log/apache2/. Look at error.log first.
Which one should you learn first?
My suggestion:
- If you mostly work with WordPress and PHP sites on shared hosting, learn how Apache and
.htaccesswork, because you will deal with them constantly. - If you are setting up your own VPS for a Node, Python or Laravel app, start with Nginx. The config is easy to reason about and most tutorials assume it.
Honestly, after you have learnt one properly, picking up the other takes a day or two. The concepts are the same: virtual hosts or server blocks, document roots, rewrites, proxying and TLS. Only the syntax changes.