L
L
Lelouch2020-05-12 16:29:32
Nginx
Lelouch, 2020-05-12 16:29:32

Why did this nginx config stop working after upgrading Ubuntu from 18.04 to 20.04?

Good afternoon!

I tried to upgrade the server to Ubuntu 20.04 and was forced to roll back to backup, because. one of the sites stopped working normally, and I couldn’t figure out why on my own.

There is this config:

server {
    listen 443 ssl http2;
    server_name domain.tld;
    root /var/www/domain.tld;
    index index.php index.html;
    autoindex off;

    location / {
        try_files $uri $uri/ /$uri.php$is_args$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_intercept_errors on;
        fastcgi_index index.php;
        try_files $uri =404;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~* \.(css|js|gif|ico|jpeg|jpg|png|svg|svgz|woff|woff2|ttf|otf|eot|json)$ {
        expires max;
    }

    location /l/ {
        rewrite ^/l/([a-zA-Z0-9/]+)$ /l.php?i=$1 last;
    }

    location /t/ {
        rewrite ^/t/([a-zA-Z0-9/]+)$ /t.php?i=$1 last;
    }

    location /w/ {
        rewrite ^/w/([a-zA-Z0-9/]+)$ /w.php?i=$1 last;
    }

    location /confirm/ {
        rewrite ^/confirm/(.*)$ /confirm.php?i=$1 last;
    }

    location /unsubscribe/ {
        rewrite ^/unsubscribe/(.*)$ /unsubscribe.php?i=$1 last;
    }

    location /subscribe/ {
        rewrite ^/subscribe/(.*)$ /subscribe.php?i=$1 last;
    }

    ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}


The problem is that after the update, nginx goes into a timeout.

If you do it like this:
location / {
        try_files $uri /$uri.php$is_args$args;
    }


It starts to open pages, but in this case, my site stops working as expected. :)

Initially, the engine assumes that it will run on Apache. Maybe I did something wrong when translating the rules for nginx? Here is the original .htaccess:
Options +FollowSymLinks
Options -Multiviews

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9-]+)$ $1.php [L]

# Link tracker
RewriteRule ^l/([a-zA-Z0-9/]+)$ l.php?i=$1 [L]

# Open tracker
RewriteRule ^t/([a-zA-Z0-9/]+)$ t.php?i=$1 [L]

# Web version
RewriteRule ^w/([a-zA-Z0-9/]+)$ w.php?i=$1 [L]

# unsubscribe
RewriteRule ^unsubscribe/(.*)$ unsubscribe.php?i=$1 [L]

# subscribe
RewriteRule ^subscribe/(.*)$ subscribe.php?i=$1 [L]


PS: Also, I would be grateful for any comments on how to make the config better or what to read about how to do it right.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Karasik, 2020-05-12
@vitaly_il1

We need to check the logs.
Perhaps PHP configs in other places, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question