Serving static files Debian 11 & Nginx (no Apache)

Hello and here we go again,

I checked DC and this forum for relevant information, but could not successfully solve my issue.

Setup:
[ Debian 11 ] [ Nginx only ] [ default.tpl/.stpl copies ] [ PHP-FPM_7.4 ] [ SSL ]

I am trying out a forum framework called Codoforums from Codologic. I have used it before, it is based on PHP and everything was ok.

The forum runs without issues using a copy of default.tpl & default.stpl templates. The issue is with loading and uploading some content like images.

Images from this specific folder are being opened and displayed. Also these are hardcoded into sql database with original names:

%sdocroot%/sites/default/assets/img/cats

Other images are not shown and are located in couple of subfolders:

%sdocroot%/sites/default/assets/img/attachments
%sdocroot%/sites/default/assets/img/profiles
... etc [same img folder with subfolders]

/sites/default/assets/img/cats/3d-printing-services-500x500.png [OK]
/sites/default/assets/img/profiles/icons/A_7f0044.png [Nginx Error]

Now some interesting part: some image names (from the ones that dont show) are generated and some are hardcoded:
/sites/default/assets/img/profiles/icons/A_7f0044.png [ Hardcoded ]
while
/sites/default/assets/img/attachments/ [ Generated ]

In database they show as:

and in folder:

folder

So I am working on understanding the script that loads some image files as it is something like:
*domain*/CODOF_RURI_60e20ae9e9f45_serve/attachment&path=61acfd6d4bede

But: Maybe its fpm-php7.4 or static file nginx block issue?

Observations:

  • Because images are not loading, I tried to open one by generated link and link itself is fine, but I get Nginx 404 error. I know default template is working with Nginx+apache2, so maybe thats the problem. And it just gives me a vibe of a static file serving problem.

  • I obviously would not be posting new thread if I haven’t tried different configurations. I have tried adding include /etc/nginx/mime.types to server block with no luck. Also tried adding try_files $url $url/ =404 to location block with no luck either.

My SSL file below with some the changes:

#=========================================================================#
# Default Web Domain Template                                             #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS   #
# https://docs.hestiacp.com/admin_docs/web.html#how-do-web-templates-work #
#=========================================================================#

server {
    listen      %ip%:%web_ssl_port% ssl http2;
    server_name %domain_idn% %alias_idn%;
    root        %sdocroot%;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/%domain%.log combined;
    access_log  /var/log/nginx/domains/%domain%.bytes bytes;
    error_log   /var/log/nginx/domains/%domain%.error.log error;

    ssl_certificate      %ssl_pem%;
    ssl_certificate_key  %ssl_key%;
    ssl_stapling on;
    ssl_stapling_verify on;

    include %home%/%user%/conf/web/%domain%/nginx.hsts.conf*;
	include /etc/nginx/mime.types;

    location / {
        # serve static files
		location ~ ^/(images|javascript|js|css|static)/  {
		  root %sdocroot%/sites/default/assets/;
		  expires 30d;
		}
		
		#location ~* ^.+\.(jpeg|jpg|png|webp|gif|bmp|ico|svg|css|js)$ {
                #expires max;
                #fastcgi_hide_header "Set-Cookie";
		#}

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    %backend_lsnr%;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
            include     %home%/%user%/conf/web/%domain%/nginx.fastcgi_cache.conf*;
        }
    }

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location ~ /\.(?!well-known\/) {
       deny all;
       return 404;
    }
	location /vstats/ {
        alias   %home%/%user%/web/%domain%/stats/;
        include %home%/%user%/web/%domain%/stats/auth.conf*;
    }

    proxy_hide_header Upgrade;

    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     %home%/%user%/conf/web/%domain%/nginx.ssl.conf_*;
}

[ I am testing everything over SSL only and therefore I did not edit the default.tpl and left is as default template entry ]

I commented out

#location ~* ^.+\.(jpeg|jpg|png|webp|gif|bmp|ico|svg|css|js)$ {
                #expires max;
                #fastcgi_hide_header "Set-Cookie";
		#}

because I checked the syntax in regex and it does not match generated link syntax. Also I believe this is really for apache?

  • Some documents say that I need to configure my php.ini file to have these entries as below:
file_uploads = On
allow_url_fopen = On
short_open_tag = On
cgi.fix_pathinfo = 0
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
max_input_vars = 1500

So I checked the php.ini file for php-fpm_7.4 - it has file_uploads and allow_url_fopen enabled anyways, so did not change anything else, and I think that would be wrong way of doing it.

  • Lastly, when I tried this setup on ubuntu, I installed all php repos manually and also their extensions. Now, I do not recall what those extensions were, but its someting like curl. So maybe I am missing some of those.

I can pull some logs/error logs later if required from: /var/log/nginx/domains.

If there is a huge chance that this issue is not Hestia/nginx related, then just let me know and I will look for a proper forum for such issue.

I will be updating my progress, thanks for reading in :slight_smile:

Ok, something new here:

So I managed to find the extensions it should have:

sudo apt install php7.4-fpm php7.4-common php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-mysql php7.4-gd php7.4-bcmath php7.4-xml php7.4-cli php7.4-zip

Maybe ignore this post until my next update, because before wasting your time, I would like to waste some of mine to confirm that php side (and forum framework) is not bugged.

I am not deleting this Post, just in case it is the nginx issue and I will have to come back to it.

By running dpkg --get-selections | grep -i php

php7.4-apcu                                     install
php7.4-apcu-bc                                  install
php7.4-bcmath                                   install
php7.4-bz2                                      install
php7.4-cli                                      install
php7.4-common                                   install
php7.4-curl                                     install
php7.4-fpm                                      install
php7.4-gd                                       install
php7.4-imagick                                  install
php7.4-imap                                     install
php7.4-intl                                     install
php7.4-json                                     install
php7.4-ldap                                     install
php7.4-mbstring                                 install
php7.4-mysql                                    install
php7.4-opcache                                  install
php7.4-phpdbg                                   install
php7.4-pspell                                   install
php7.4-readline                                 install
php7.4-soap                                     install
php7.4-xml               

Because I use 7.4, im missing some… add them manually?

Solution was to remove all php7.4 packages and the install them again:
Remove using:

  • v-remove-web-php [ and then purge any remaining packages if you had extra ]

Then add using:

  • sudo /usr/local/hestia/bin/v-add-web-php
1 Like

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