How to Fix Nginx 403 Forbidden Errors on a Fresh VPS

A fresh VPS, a clean Nginx install, and a browser that says 403 Forbidden. The server is running, the domain resolves, and yet nothing loads. A fix nginx 403 forbidden error usually comes down to a handful of causes, and the error log names the culprit in plain language. Work through the checks below in order.

Fix Nginx 403 Forbidden: What the Error Actually Means

A 403 response means Nginx understood the request and refused it on purpose. The file or directory exists in the configuration, but the worker process is not allowed to read it, or the configuration tells Nginx to serve something that is not there. That distinction matters. A 404 means “not found.” A 403 means “found, but no.”

On a fresh VPS the usual suspects are file permissions, wrong ownership, a missing index file, a root directive pointing at the wrong folder, or a PHP-FPM socket the web server cannot reach. Permissions cause most of them.

Confirm it is real first: curl -I https://example.com from your own machine should also return 403.

Step 1: Read the Nginx Error Log First

The nginx error log names the exact file and the exact reason, and reading it takes ten seconds. On Ubuntu and Debian the log lives at /var/log/nginx/error.log. Tail it while you reproduce the error:

sudo tail -f /var/log/nginx/error.log

Then reload the page. You will see lines like these, and each one points at a different fix:

  • open() "/var/www/html/index.html" failed (13: Permission denied): a permission or ownership problem. Go to Step 2.
  • directory index of "/var/www/html/" is forbidden: no index file and directory listing is off. Go to Step 3.
  • connect() to unix:/run/php/php8.3-fpm.sock failed (13: Permission denied): PHP-FPM socket permissions. Go to Step 4.
  • open() "/var/www/missing/index.html" failed (2: No such file or directory): the root path is wrong. Go to Step 3.

If the log is empty, check for a custom error_log directive in the active server block. Knowing where Nginx keeps its access and error logs and how to read them saves blind searching on every future problem.

Step 2: Fix File Permissions and Ownership

This is the most common cause on a fresh VPS. Files are often created as root or uploaded as a different user, while Nginx runs as www-data on Ubuntu and Debian. The worker process needs execute permission on every directory in the path and read permission on the files themselves. When that chain breaks, you get the classic nginx permission denied entry in the log.

Start by checking what you actually have:

ls -ld /var/www /var/www/html
ls -l /var/www/html

A healthy document root has directories at 755 and files at 644, owned by the deploy user or www-data. Set them with:

sudo chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 755 {} ;
sudo find /var/www/html -type f -exec chmod 644 {} ;

Two mistakes show up constantly. The first is chmod 777. It “fixes” the error by letting everyone read and write everything, and it leaves the site open to any other process or user on the box. Never use it. The second is fixing permissions on the files but not on a parent directory. Nginx needs execute permission on every directory down to the file, so one locked parent blocks the whole path. If you want the full picture of how ownership and modes interact, read our guide on Linux file permissions and how to secure /var/www the right way.

Step 3: Check the Root Directive and the Index File

Open the active server block, usually in /etc/nginx/sites-enabled/, and read the root and index lines:

sudo nginx -T | grep -A 5 "server_name example.com"

The root path must be the directory that actually holds your files. A fresh install defaults to /var/www/html, but tutorials often create /var/www/example.com/html and forget to update the server block or create the directory. If the directory does not exist, create it and add an index file, or correct the root path to match reality.

Next, confirm an index file exists and matches the index directive:

ls /var/www/html
grep -r "index" /etc/nginx/sites-enabled/example.com

If the directive says index index.html index.htm; but the folder only holds index.php, Nginx finds no directory index and returns 403. Either add the missing index file or add its name to the directive. For a PHP site the directive usually reads index index.php index.html index.htm;.

Do not “fix” this by turning on autoindex on;. That exposes a browsable listing of every file in the directory to anyone who asks. If you are still setting up server blocks, our walkthrough on how to set up Nginx server blocks on Ubuntu 24.04 covers root, index, and symlinks, so the structure is right from the start.

Step 4: Fix PHP-FPM Socket Permissions

If static files load but PHP pages return 403, the problem is usually between Nginx and PHP-FPM. The two processes talk through a Unix socket, and Nginx must be allowed to write to it. The error log line to look for is connect() to unix:/run/php/php8.3-fpm.sock failed (13: Permission denied).

Check the socket and its owner:

ls -l /run/php/
grep -E "listen.(owner|group|mode)" /etc/php/8.3/fpm/pool.d/www.conf

The standard working setup is listen.owner = www-data, listen.group = www-data, and listen.mode = 0660. If the pool runs as a different user, or the socket mode is too tight, Nginx gets turned away. Edit the pool file, then restart PHP-FPM:

sudo systemctl restart php8.3-fpm
sudo systemctl reload nginx

Also confirm the version numbers match. After a PHP upgrade, the old socket path may point at a version that no longer exists, for example php8.2-fpm.sock after moving to PHP 8.3. Update the fastcgi_pass line to the socket that actually exists on disk.

Step 5: Check AppArmor and SELinux

On Ubuntu, AppArmor can block Nginx from reading files outside its usual paths even when permissions look correct. That bites when the document root sits somewhere unusual, like a mounted drive, and it is a common cause of a stubborn nginx 403 forbidden ubuntu case where every chmod seems to change nothing. Check the audit log for denials:

sudo grep -i denied /var/log/syslog | grep -i nginx
sudo aa-status | grep nginx

If you see denials tied to your document root, move the site under /var/www, which AppArmor permits by default, or add a profile exception for the new path. Do not disable AppArmor server-wide to get past one error.

SELinux does the same thing on AlmaLinux and Rocky Linux through file contexts; restore them with restorecon -Rv /var/www/html.

Step 6: Test the Configuration and Reload

After any fix, test before you reload. A typo in a server block can take every site on the server down, not just the one you are fixing:

sudo nginx -t
sudo systemctl reload nginx

nginx -t reports syntax errors with the file and line number. Fix those first, reload, and request the page again. If it still returns 403, go back to the error log and chase the cause that remains.

Make testing before every reload a habit. Our guide on how to test a new Nginx config without taking your site down shows the same check plus a staging approach for changes you are less sure about.

Quick Checklist

  • Reproduce with curl -I and read /var/log/nginx/error.log while doing it.
  • Directories 755, files 644, owned by www-data or your deploy user, with execute permission on every parent directory.
  • root points at a directory that exists and holds an index file named in the index directive.
  • PHP-FPM socket owned by www-data with mode 0660, and fastcgi_pass pointing at the socket that exists.
  • AppArmor or SELinux not silently blocking the document root.
  • nginx -t passes, then systemctl reload nginx.

If the site worked and then broke, the last change is the prime suspect: a deploy that reset ownership to root, a copied server block with paths that do not exist here, or a PHP upgrade that moved the socket. A 403 on one URL only, while the rest of the site loads, points at a location block instead, usually a deny all; rule that matches more than intended. Most 403 errors on a fresh VPS are a permission problem, and the log names it directly. Read the log, fix the one thing it points at, test the config, and reload. The same log-first approach works for the error that usually follows a 403 once the path is corrected, as our guide on how to fix Nginx 404 errors on a fresh install shows.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.