Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference configuration for caddy2 server #43

Open
freefly42 opened this issue Aug 25, 2021 · 0 comments
Open

Reference configuration for caddy2 server #43

freefly42 opened this issue Aug 25, 2021 · 0 comments

Comments

@freefly42
Copy link

I've created a Caddyfile to enable using Caddy2 as the web server, and thought I would share. I'd suggest adding this as mythweb.conf.caddy.

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

# Global options https://caddyserver.com/docs/caddyfile/options
{
	auto_https off
	admin off
	log {
		output file /var/log/caddy/caddy.log {
			roll_size 50
			roll_keep 5
			roll_keep_for 2d
		}
		format console
		level INFO
		#level   DEBUG
	}
}

:8080 {
	# Set this path to your site's directory.
	root * /usr/share/caddy/mythweb

	# Add trailing slash for directory requests
	@canonicalPath {
		file {path}/mythweb.php
		not path */
	}
	redir @canonicalPath {path}/ 308

	# Enable the static file server.
	file_server

	# rewrite rules
	@myth_do_nothing {
		path_regexp myth_do_nothing_reg ^/(css|data|images|js|themes|skins|[a-z_]+\.(php|pl)).*
	}
	@myth_perl {
		path_regexp myth_perl_reg ^/(pl(/.*)?)$
	}
	@myth_php {
		path_regexp myth_php_reg ^/(.+)$
	}
	handle @myth_do_nothing {
		#do nothing but keep other handlers from running
		#rewrite @myth_do_nothing {http.regexp.myth_do_nothing_reg.0}
	}
	handle @myth_perl {
		rewrite @myth_perl /mythweb.pl/{http.regexp.myth_perl_reg.1}
	}
	handle @myth_php {
		rewrite @myth_php /mythweb.php/{http.regexp.myth_php_reg.1}
	}
	handle * {
		rewrite * mythweb.php
	}

	# Proxy PHP files to the FastCGI responder
	@phpFiles path *.php*
	reverse_proxy @phpFiles unix//run/php/php7.4-fpm.sock {
		transport fastcgi {
			split .php
			env db_server localhost
			env db_name mythconverg
			env db_login mythtv
			env db_password mythtv
		}
	}
}

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant