NGINX: Help fixing Config file please

I had a friend help me set up a wordpress website about a year ago using an NGINX config. It also worked with Grav but doesn’t work with Kirby. The Kirby template creator for Zero One said it was probably because of Rewrite that I’m unable to use it properly (front end theme just doesn’t show right like no themed menu and styling is missing). I’m on Ubuntu 18.04 currently.

I’d try to ask my friend for help fixing this issue, but can’t really do that without sharing the files with him. Being a paid theme I wouldn’t think it would be the right thing to do. He has no knowledge of how the files work in Kirby to help get this working and I can’t find an example template that is free that might help him that is properly themed/styled.

Here’s the Config via Pastebin.

There are a few threads on this in the forum. You could try this one…

I know how to work with Kirby, just not configuration issues for the server side. This seems more picky than using other CMS software.

I did forward this config to my friend that has been helping me maintain the NGINX setup. The config files I looked at before were more messy than this one so thanks for linking to it.

I ended up sharing this with my friend to get this working. This was the nginx config file that he came up with.

> server {
>    if ($host = www.website.com) {
>        return 301 https://$host$request_uri;
>    } # managed by Certbot
> 
> 
>    if ($host = website.com) {
>         return 301 https://$host$request_uri;
>    } # managed by Certbot
> 
>   listen 80;
>   server_name website.com www.website.com;
>   access_log /var/log/nginx/access.log;
>   error_log /var/log/nginx/error.log;
>   root /srv/website.com;
>   client_max_body_size 100m;
>   location / {
>     index index.php;
>   }
>   location /.well-known/acme-challenge {
>     root /srv/website.com/letsencrypt;
>   }
>   location ~ \.php$ {
>     fastcgi_split_path_info ^(.+?\.php)(/.*)$;
>     if (!-f $document_root$fastcgi_script_name) {
>       return 404;
>     }
>     # Mitigate https://httpoxy.org/ vulnerabilities
>     fastcgi_param HTTP_PROXY "";
>     fastcgi_pass 127.0.0.1:9000;
>     fastcgi_index index.php;
>     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
>     include /etc/nginx/fastcgi_params;
>   }
> }
> server {
>   listen 443;
>   ssl on;
>     ssl_certificate /etc/letsencrypt/live/website.com/fullchain.pem; # managed by Certbot
>     ssl_certificate_key /etc/letsencrypt/live/website.com/privkey.pem; # managed by Certbot
>   server_name website.com www.website.com;
>   access_log /var/log/nginx/ssl-access.log;
>   error_log /var/log/nginx/ssl-error.log;
>   root /srv/website.com;
>   client_max_body_size 100m;
> 
>   #website links
>   location / {
>     try_files $uri $uri/ /index.php$is_args$args;
>     index index.php;
>     add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
>     add_header Access-Control-Allow-Origin $http_origin;
>     if ($request_method = OPTIONS) {
>         add_header Content-Length 0;
>         add_header Content-Type text/plain;
>         add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
>         add_header Access-Control-Allow-Origin $http_origin;
>         add_header Access-Control-Allow-Headers "Authorization, Content-Type, Access-Control-Allow-Origin";
>         add_header Access-Control-Allow-Credentials true;
>         return 200;
>     }
>   }
>   location /server-status {
>     stub_status on;
>     access_log false;
>     allow 127.0.0.1;
>     deny all;
>   }
> 
>     location /assets {
>       rewrite uikit.min.(\d+).js uikit.min.js permanent;
>       rewrite uikit-icons.min.(\d+).js uikit-icons.min.js permanent;
>       rewrite uikit.app.min.(\d+).css uikit.app.min.css permanent;
>       try_files $uri =404;
>       expires max;
>       access_log off;
>       add_header Pragma public;
>       add_header Cache-Control "public, must-revalidate, proxy-revalidate";
>     }
> 
>     location /content {
>       try_files $uri =404;
>       expires max;
>       access_log off;
>       add_header Pragma public;
>       add_header Cache-Control "public, must-revalidate, proxy-revalidate";
>     }
> 
>     location ~ \.php$ {
>       fastcgi_split_path_info ^(.+?\.php)(/.*)$;
>       if (!-f $document_root$fastcgi_script_name) {
>         return 404;
>       }
>       # Mitigate https://httpoxy.org/ vulnerabilities
>       fastcgi_param HTTP_PROXY "";
>       fastcgi_pass 127.0.0.1:9000;
>       fastcgi_index index.php;
>       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
>       include /etc/nginx/fastcgi_params;
>     }
1 Like

Note that this was for the Zero One theme. The files for uikit kept changing file names on us when we were getting it close to getting it working. You can see the warnings for it at that point in the browser developer console. Which is why there is a permanent flag in the assets directory.

1 Like

Great, @dracmas you solved it. :slight_smile:

I would just note that it is not some Zero One/UIkit custom thing, CSS/JS files are cached with the help of the Cachebuster plugin and if the URL rewrites on a server is not working, files URLs break.

Good thing is that Timo included config option, so it is easily turned off

return [
  'schnti.cachebuster.active' => false,
];

But, we will make it optional in an update in a few days. It will be set to false by default, and only who wants can enable it.