Update Caddy config and wp-setup.sh template

This commit is contained in:
2025-01-02 10:16:08 +09:00
parent 4c99a1c8bd
commit 8e9753c405
4 changed files with 124 additions and 54 deletions
+34 -36
View File
@@ -41,47 +41,45 @@ install_site() {
setup_directories setup_directories
DOMAIN="$1" DOMAIN="$1"
#db_prefix="$(openssl rand -base64 6)"_
WP_PROJECT_DIR="${WORDPRESS_DIR}/${DOMAIN}"
while true; do if [ -d "$WP_PROJECT_DIR" ]; then
read -p "Enter admin email: " ADMIN_EMAIL echo -e "${RED}Directory ${WP_PROJECT_DIR} already exists!${NC}"
if validate_email "$ADMIN_EMAIL"; then exit 1
break
fi fi
done
read -p "Enter admin username: " ADMIN_USER
read -s -p "Enter password (press Enter for random password): " ADMIN_PASSWORD
echo
if [ -z "$ADMIN_PASSWORD" ]; then
ADMIN_PASSWORD=$(generate_password)
echo "Generated password: $ADMIN_PASSWORD"
fi
read -p "Enter site title: " SITE_TITLE
MYSQL_ROOT_PASSWORD=$(openssl rand -base64 32)
MYSQL_PASSWORD=$(openssl rand -base64 32)
WP_PROJECT_DIR="${WORDPRESS_DIR}/${DOMAIN}"
if [ -d "$WP_PROJECT_DIR" ]; then
echo -e "${RED}Directory ${WP_PROJECT_DIR} already exists!${NC}"
exit 1
fi
mkdir -p "$WP_PROJECT_DIR"
cd "$WP_PROJECT_DIR"
create_docker_compose "$DOMAIN" "$MYSQL_ROOT_PASSWORD" "$MYSQL_PASSWORD"
create_caddy_config "$DOMAIN"
create_wp_setup "$DOMAIN" "$ADMIN_USER" "$ADMIN_PASSWORD" "$ADMIN_EMAIL" "$SITE_TITLE"
create_env_file "$DOMAIN" "$ADMIN_USER" "$ADMIN_PASSWORD" "$ADMIN_EMAIL" "$MYSQL_ROOT_PASSWORD" "$MYSQL_PASSWORD"
while true; do
read -p "Enter admin email: " ADMIN_EMAIL
if validate_email "$ADMIN_EMAIL"; then
break
fi
done
read -p "Enter admin username: " ADMIN_USER
read -s -p "Enter password (press Enter for random password): " ADMIN_PASSWORD
echo
if [ -z "$ADMIN_PASSWORD" ]; then
ADMIN_PASSWORD=$(generate_password)
echo "Generated password: $ADMIN_PASSWORD"
fi
read -p "Enter site title: " SITE_TITLE
MYSQL_ROOT_PASSWORD=$(openssl rand -base64 32)
MYSQL_PASSWORD=$(openssl rand -base64 32)
mkdir -p "$WP_PROJECT_DIR"
cd "$WP_PROJECT_DIR"
create_docker_compose "$DOMAIN" "$MYSQL_ROOT_PASSWORD" "$MYSQL_PASSWORD"
create_caddy_config "$DOMAIN"
create_wp_setup "$DOMAIN" "$ADMIN_USER" "$ADMIN_PASSWORD" "$ADMIN_EMAIL" "$SITE_TITLE"
create_env_file "$DOMAIN" "$ADMIN_USER" "$ADMIN_PASSWORD" "$ADMIN_EMAIL" "$MYSQL_ROOT_PASSWORD" "$MYSQL_PASSWORD"
while true; do while true; do
+32
View File
@@ -33,6 +33,38 @@ create_caddy_docker_compose() {
admin off admin off
persist_config off persist_config off
} }
(wordpress) {
# Some static files Cache-Control.
@static {
path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.json
}
header @static Cache-Control max-age=2592000
# Security
@forbidden {
not path /wp-includes/ms-files.php
path /wp-admin/includes/*.php
path /wp-includes/*.php
path /wp-config.php
path /wp-content/uploads/*.php
path /.user.ini
path /wp-content/debug.log
}
respond @forbidden "Access denied" 403
# Cache Enabler
@cache_enabler {
not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
not path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
not method POST
not expression {query} != ''
}
route @cache_enabler {
try_files /wp-content/cache/cache-enabler/{host}{uri}/https-index.html /wp-content/cache/cache-enabler/{host}{uri}/index.html {path} {path}/index.php?{query}
}
}
# Site configurations will be imported below # Site configurations will be imported below
import sites/*.caddy import sites/*.caddy
+2 -2
View File
@@ -1,7 +1,6 @@
${DOMAIN} { ${DOMAIN} {
#reverse_proxy wordpress_${DOMAIN}:80
tls internal #tls internal
root * /var/www/${DOMAIN}/html root * /var/www/${DOMAIN}/html
encode zstd gzip encode zstd gzip
@@ -18,5 +17,6 @@ ${DOMAIN} {
X-Frame-Options "SAMEORIGIN" X-Frame-Options "SAMEORIGIN"
X-Content-Type-Options "nosniff" X-Content-Type-Options "nosniff"
} }
import wordpress
} }
+54 -14
View File
@@ -11,20 +11,60 @@ while [ "$(docker inspect --format='{{.State.Health.Status}}' db_${DOMAIN})" !=
sleep 5 sleep 5
done done
if ! wpcli core is-installed ; then
echo "Installing WordPress..."
wpcli core install \
--url="https://${DOMAIN}" \
--title="${SITE_TITLE}" \
--admin_user="${ADMIN_USER}" \
--admin_password="${ADMIN_PASSWORD}" \
--admin_email="${ADMIN_EMAIL}" \
--skip-email
echo "Installing WordPress..." echo "Installing and activating plugins..."
wpcli core install \ wpcli plugin install wordfence cache-enabler --activate
--url="https://${DOMAIN}" \ wpcli option update cache_enabler '{
--title="${SITE_TITLE}" \ "version": "1.8.15",
--admin_user="${ADMIN_USER}" \ "use_trailing_slashes": 1,
--admin_password="${ADMIN_PASSWORD}" \ "permalink_structure": "has_trailing_slash",
--admin_email="${ADMIN_EMAIL}" \ "cache_expires": 1,
--skip-email "cache_expiry_time": 8,
"clear_site_cache_on_saved_post": 0,
"clear_site_cache_on_saved_comment": 0,
"clear_site_cache_on_saved_term": 0,
"clear_site_cache_on_saved_user": 0,
"clear_site_cache_on_changed_plugin": 0,
"convert_image_urls_to_webp": 0,
"mobile_cache": 0,
"compress_cache": 1,
"minify_html": 1,
"minify_inline_css_js": 1,
"excluded_post_ids": "",
"excluded_page_paths": "",
"excluded_query_strings": "",
"excluded_cookies": ""
}' --format=json
echo "Installing and activating plugins..." wpcli theme install kadence --activate
wpcli plugin install wordfence --activate wpcli plugin update --all
wpcli theme install twentytwentyfour --activate wpcli theme update --all
wpcli plugin update --all
wpcli theme update --all
echo "WordPress setup completed!" # List users
echo "== User List =="
wpcli user list
echo ""
# Show installed plugin
echo "== Theme List =="
wpcli theme list
echo ""
# Show installed plugin
echo "== Plugin List =="
wpcli plugin list
echo ""
echo "WordPress setup completed!"
else
echo "WordPress is already installed. Exiting now..."
fi