Problem with deleting www (redirect)

Hello everyone!

Ubuntu 20.04
Nginx 1.18.0
Certbot nginx

Got 2 certificates for and
I don’t want that www before my site and put a redirect to without www

Here’s a code from mysite.conf in nginx which edited certbot

server {
  root /var/www/forum;
  index index.php;

  location ~* /\.git { deny all; return 403; }
  location /build/ { deny all; return 403; }
  location /cache/ { deny all; return 403; }
  location /cgi-bin/ { deny all; return 403; }
  location /uploads/import/ { deny all; return 403; }
  location /conf/ { deny all; return 403; }
  location /tests/ { deny all; return 403; }
  location /vendor/ { deny all; return 403; }

  location ~* ^/index\.php(/|$) {
    include snippets/fastcgi-php.conf;
    fastcgi_param SCRIPT_NAME /index.php;
    fastcgi_param SCRIPT_FILENAME $realpath_root/index.php;
    fastcgi_param X_REWRITE 1;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

  location ~* \.php(/|$) {
    rewrite ^ /index.php$uri last;

  location / {
    try_files $uri $uri/ @forum;

  location @forum {
    rewrite ^ /index.php$uri last;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

server {
    if ($host = {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = {
        return 301 https://$host$request_uri;
    } # managed by Certbot

  listen 80;
    return 404; # managed by Certbot


I added this

server {
return 301 $scheme://$request_uri;

But nothing has changed. It worked until I installed cerbot.
How to fix it please?

Also one question. Maybe in that case I shouldn’t have asked for a cert for Just for

Thank you!

And the cert says it from 25.05.20. Why 25.05? I installed it today… Maybe it shows my previous instalation but it was on the VPS I deleted a week ago…


I think that might not work is because you already had both HTTP and HTTPS version of that host specified.
You can try to add the below code snippet to your HTTPS configuration file.

if ($host = '') {
  rewrite ^/(.*)$$1 permanent;

Without knowing the domain name and your exact configuration, I’m suspecting it’s either you requested the certificate but didn’t delete it (if you created a new one today) or you didn’t reload your web server.

Because I delete the VPS after it. If I only knew that first I need to delete the sertificated… Any chance to delete it at all or all the chances had gone when I deleted the VPS?

Didn’t help :confused:

I had almost the same configuration from my website…
Did you restart your Nginx server?
What’s the complete configuration in your https conf file now?

If you deleted your VPS without saving the certificate and redo the installation, there’s no way your server will pickup the old certificate. Maybe it’s the old cache? Try to open your website on another machine or browser.

Yes of course.

Just like it was. I added your lines but it didn’t help so I deleted them.

Maybe it’s because of Cloudlfare? CF sees my OLD cert and IDK how to delete it :confused:

This looked weird.
It just looks like CloudFlare are issuing Universal Certificate from Let’s Encrypt CA? (I thought they issue from Sectigo and DigiCert CA)
If this is the one, you don’t need to worry about that.
This is managed automatically by CloudFlare and they’ll renew it as needed. (If you delete it, visitors will never be able to view your website unless you move away from CloudFlare)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.