Help with basic fastcgi problem

I’m trying to migrate my PHP based (fastcgi via php7-fpm) nginx conf to caddy. Basically, the site is up and running, but the CSS file is not yet included.

The (working) nginx conf was quite simple:

server {
	listen 80 default_server;
	listen [::]:80 default_server;
	root /var/www/wikindx;
	index index.php index.html index.htm index.nginx-debian.html;
	server_name <my-site>;
	location / {
		try_files $uri $uri/ =404;
	}
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
	}
}

Contents of the included snippets/fastcgi-php.conf (which came with nginx):

# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+?\.php)(/.*)$;

# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

fastcgi_index index.php;
include fastcgi.conf;

By now, I have the following Caddyfile:

www.mysite.de {
	root /var/www/wikindx
	log /var/log/caddy/access.log {
		rotate_size 50  # Rotate after 50 MB
		rotate_age  90  # Keep rotated files for 90 days
		rotate_keep 20  # Keep at most 20 log files
		rotate_compress # Compress rotated log files in gzip format
	}
	errors /var/log/caddy/error.log {
		rotate_size 50
		rotate_age  90
		rotate_keep 20
		rotate_compress
	}
	gzip
	fastcgi / /run/php/php7.0-fpm.sock php
}

With that I get the basic HTML file, but without CSS. The CSS file is located in a subdirectory of the root file directory. How can I get the CSS file included?

Your nginx configuration doesn’t do any special handling for CSS. How did your site serve its CSS previously?

Ideally, the link tags in your HTML documents should point to the right subdirectory. If that can’t be done, you can look into rewriting CSS requests to the right place:

https://caddyserver.com/docs/rewrite

Hmm, not much of a HTML or CSS wizard here. My site is serving a bibliographic database running on WIKINDX (hence the template paths). The site runs flawlessly with those nginx code bits I showed out of the box. In the HTML header, I have

<link rel="stylesheet" href="https://<my-site>/templates/simpleBlue/template.css" type="text/css">
<link rel="shortcut icon" type="image/x-icon" href="https://<my-site>/templates/simpleBlue/images/favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

I looked at the Chrome DevTools output, and there are several files in subdirectories which get a 404 with my Caddy conf:

GET https://<mysite>/templates/simpleBlue/template.css net::ERR_ABORTED 404
GET https://<mysite>/core/javascript/coreJavascript.js net::ERR_ABORTED 404
GET https://<mysite>/core/ajax/json2.js net::ERR_ABORTED 404
GET https://<mysite>/templates/simpleBlue/template.js net::ERR_ABORTED 404
GET https://<mysite>/plugins/chooseLanguage/chooseLanguage.js net::ERR_ABORTED 404
GET https://<mysite>/templates/simpleBlue/images/wikindx-logo-anim.gif 404
GET https://<mysite>/templates/simpleBlue/icons/rss.png 404

This last one is really weird because there are several PNG files in the same directory (/var/www/wikindx/templates/simpleBlue/icons) which have no problems … Any clues how to rewrite or redirect these files?

Hmm. You could try putting in your Caddyfile:

rewrite {
  to {path} {path}/ /
}

…as the conventional Caddy approximation of the nginx conf:

	location / {
		try_files $uri $uri/ =404;
	}

Stupid mistake here with config.php. All is well, sorry to have bothered you!