Magento Nginx and the nginx.conf.sample file

Point Nginx at Magento by setting MAGE_ROOT and including nginx.conf.sample. That file serves pub. Do not also invent a second document root.

Last updated: October 26, 2026

Visitors must not be able to request app/etc/env.php. Adobe’s nginx.conf.sample, included from the vhost, serves the shop from pub even when $MAGE_ROOT points at the project root. A missing sites-enabled folder, a missing nano, and a certbot lock error are three different problems. Only the first one is about where the vhost lives.

Illustration of three host messages: sites-enabled missing, nano not found, and a certbot lock permission error.
Illustration. These are three different host messages. This is not a capture from a server.

The messages

ls: cannot access '/etc/nginx/sites-enabled': No such file or directory
bash: nano: command not found
[Errno 13] Permission denied: '/var/log/letsencrypt/.certbot.lock'

nano is an editor. Its absence does not stop TLS. Use vi, or install nano if you want that editor. Do not treat the install as the certificate fix.

Find how this Nginx loads vhosts

Debian and Ubuntu include /etc/nginx/sites-enabled. RHEL, many Docker images, and some panels include /etc/nginx/conf.d/*.conf and never create sites-enabled. Creating sites-enabled and a symlink does nothing if nginx.conf does not include that directory.

nginx -V 2>&1 | tr ' ' '\n' | grep conf-path
grep -n include /etc/nginx/nginx.conf

Put the Magento file in a directory that include already names. Then:

sudo nginx -t && sudo systemctl reload nginx

nginx -t must say syntax is ok before you reload. A reload of a bad file drops the sites that were working.

Use Magento’s sample

Adobe’s Nginx install page is the file to follow. The vhost sets $MAGE_ROOT to the project root and includes nginx.conf.sample. The sample then serves files from pub. The docroot note says the same thing: with that include, you are already serving pub. Do not also set root to pub yourself and fight the sample.

Ubuntu keeps vhosts in sites-available and enables one with a symlink into sites-enabled. CentOS and many containers use conf.d and have no sites-enabled at all. Use the directory this Nginx already includes.

upstream fastcgi_backend {
    server unix:/run/php/php8.3-fpm.sock;
}

server {
    listen 80;
    server_name shop.example;
    set $MAGE_ROOT /var/www/shop;
    include /var/www/shop/nginx.conf.sample;
}

Replace the socket with the one listen = in your php-fpm pool. Replace the paths. Then sudo nginx -t and reload.

The sample’s deny rules are the security control. If you skip the include and point root at the project root, env.php is on the internet. If you write your own server block, the document root has to be pub, and you still need equivalent deny rules.

After HTTPS works, set Magento’s secure and unsecure base URLs to https://your-host/ and flush config cache. A certificate with an HTTP base URL still posts the storefront to HTTP.

certbot cannot write its lock

Permission denied on /var/log/letsencrypt/.certbot.lock means this user cannot write Let’s Encrypt’s log directory. Someone else, usually root, created it. Paste the mode from ls -ld into the chmod calculator to see whether owner, group, or other can write.

ls -ld /var/log/letsencrypt /var/log/letsencrypt/.certbot.lock

Run certbot the same way the package expects, which on Linux is root:

sudo certbot --nginx

Use the instructions for your OS and web server. --nginx only works when the Nginx plugin can edit the vhost. If Nginx was installed from a layout certbot does not know, use webroot or a DNS challenge instead of inventing sites-enabled.

If a certbot process is running, leave the lock. Deleting .certbot.lock while certbot is mid-renew corrupts the run. Delete it only when ps shows no certbot and you still cannot start because the file is stale and owned by a user you are not.

An expired certificate is not the lock error. After certbot can write the directory, sudo certbot certificates shows the expiry. Renew, reload Nginx, and only then change Magento’s base URL if it was still HTTP.

Run sudo nginx -t before every reload. A syntax error in the vhost keeps the previous config running, so a reload that prints nothing useful is not proof that the sample file was included.

Check the result

  • curl -I https://your-host/ returns 200 or a Magento redirect, and the certificate name matches the host.
  • curl -I https://your-host/static/ is not a listing of the Magento root.
  • https://your-host/app/etc/env.php is denied.
  • The storefront padlock stays, and the base URL config is https.

If that does not work

  • nginx -t fails on the sample because root or the fastcgi socket path is wrong. Fix the path it names. Do not comment out the deny rules to get a green test.
  • PHP returns Magento’s setup page from the project root. The vhost root is still one directory too high.
  • Port 80 is closed, so HTTP-01 cannot run. Open it for the challenge or use DNS-01. Do not switch the shop to “SSL off” to hide the failure.
  • The lock is gone and certbot now says the rate limit was hit. Wait. Another request will not issue a certificate.

References

On this page

Related guides

Related Articles

Related solutions

Need a tool for this ?

Open the free tools — no signup.

FAQs

Innovative Solutions For Modern Needs
Copyright © 2026 Yallasolve. all rights reserved.