Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rgbohner's avatar

Enabling and disabling Let's Encrypt on nginx server caused 404 error

Hello, I set up ssl using lets encypt for an nginx site. After forge indicated that is was installed the site returned a 403 error, I then uninstalled let's encrypt and now the site returns a 404 error.

Here is the nginx config

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/not_my_real_site_name/before/*;

server {
    listen 80;
    listen [::]:80;
    server_name not_my_real_site_name;
    root /home/forge/not_my_real_site_name/web;

    # FORGE SSL (DO NOT REMOVE!)
    # ssl_certificate
    # ssl_certificate_key

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/not_my_real_site_name/server/*;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd; 
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/not_my_real_site_name-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/not_my_real_site_name/after/*;

Please ignore the potato authentication, its a dev site

0 likes
1 reply
rgbohner's avatar
rgbohner
OP
Best Answer
Level 1

found the issue. It looks like disabling let's encrypt does not add "default_server" back into the listen lines of the server clause in the nginx.conf

so I changed the above file from

...
server {
    listen 80;
    listen [::]:80;
...

to

...
server {
    listen 80 default_server;
    listen [::]:80 default_server;
...

after this change, everything is back to the way it was.

Please or to participate in this conversation.