Nginx configuration - Panel working - Images 404

Trying to configure my nginx server. It’s a basic CloudPanel vhost which I adjusted according to the recommendation from the Kirby docs.

The panel is working. But files that I upload are not showing up in the backend (broken file symbol), but they get uploaded as I can see them in the folder. When trying to access the file, I get a 404 Error
e.G. :
https://tut.foxweb.dev/panel/pages/locations+prague/files/explore4.jpg

On line 40 of the Nginx config, I have
#try_files $uri $uri/ /index.php$is_args$args;
when enabling it, I can’t access the panel anymore.
Do I need this line also in the 80/443 Server block or only in the 8080

Here is my Nginx config:


server {
  listen 80;
  listen [::]:80;
  listen 443 quic;
  listen 443 ssl;
  listen [::]:443 quic;
  listen [::]:443 ssl;
  http2 on;
  http3 off;
  {{ssl_certificate_key}}
  {{ssl_certificate}}
  server_name tut.foxweb.dev;
  {{root}}

  {{nginx_access_log}}
  {{nginx_error_log}}

  if ($scheme != "https") {
    rewrite ^ https://$host$request_uri permanent;
  }

  location ~ /.well-known {
   # auth_basic off;
    allow all;
  }
  
  default_type text/plain;
  add_header X-Content-Type-Options nosniff;
  
  

  {{settings}}
  
  rewrite ^/(content|site|kirby)/(.*)$ /error last;
  rewrite ^/\.(?!well-known/) /error last;
  rewrite ^/(?!app\.webmanifest)[^/]+$ /index.php last;

  location / {
    {{varnish_proxy_pass}}
    #try_files $uri $uri/ /index.php$is_args$args;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_hide_header X-Varnish;
    proxy_redirect off;
    proxy_max_temp_file_size 0;
    proxy_connect_timeout      720;
    proxy_send_timeout         720;
    proxy_read_timeout         720;
    proxy_buffer_size          128k;
    proxy_buffers              4 256k;
    proxy_busy_buffers_size    256k;
    proxy_temp_file_write_size 256k;
  }


  location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|woff2|eot|mp4|ogg|ogv|webm|webp|zip|swf|map|mjs)$ {
    add_header Access-Control-Allow-Origin "*";
    add_header alt-svc 'h3=":443"; ma=86400';
    expires max;
    access_log off;
  }

  location ~ /\.(ht|svn|git) {
    deny all;
  }

  if (-f $request_filename) {
    break;
  }
}

server {
  listen 8080;
  listen [::]:8080;
  server_name tut.foxweb.dev;
  {{root}}

  include /etc/nginx/global_settings;

  try_files $uri $uri/ /index.php?$args;
  index index.php index.html;
  
  default_type text/plain;
  add_header X-Content-Type-Options nosniff;
  
  rewrite ^/(content|site|kirby)/(.*)$ /error last;
  rewrite ^/\.(?!well-known/) /error last;
  rewrite ^/(?!app\.webmanifest)[^/]+$ /index.php last;
  
  location / {
    try_files $uri $uri/ /index.php$is_args$args;
  }

  location ~ \.php$ {
    include fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    try_files $uri =404;
    fastcgi_read_timeout 3600;
    fastcgi_send_timeout 3600;
    fastcgi_param HTTPS "on";
    fastcgi_param SERVER_PORT 443;
    fastcgi_pass 127.0.0.1:{{php_fpm_port}};
    fastcgi_param PHP_VALUE "{{php_settings}}";
  }

  if (-f $request_filename) {
    break;
  }
}

Thanks a lot for any help.

Remove this segment. Kirby uses a router to render images, and this rule gets in the way of it resolving images to the router properly. I just fixed this same issue on my server.

1 Like

Thanks a lot, it’s working.
Already gave up on it, but now back on track :slight_smile:

A follow-up question on CloudPanel, but be careful, it might damage ur Kirby installation:
When activating basic authentication in CloudPanel i can’t login anymore. When trying to access /panel i only get “invalid login” even though i didn’t even see the login screen. Also, after switching off basic authentication, the “invalid login” screen still stays and I can’t find a way to login. After uploading the Kirby installation again, I was able to login again.