Skip to content

Commit

Permalink
Merge pull request #20 from RunOnFlux/develop
Browse files Browse the repository at this point in the history
make nginx.conf persistent
  • Loading branch information
alihm authored Feb 20, 2024
2 parents 3d82666 + bd23067 commit 52a5316
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ RUN { \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install MySQL client
RUN apt-get update && apt-get install -y default-mysql-client
RUN apt-get update && apt-get install -y default-mysql-client nano

# Install WP-CLI
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
Expand Down Expand Up @@ -208,4 +208,4 @@ EXPOSE 2222/tcp

ENTRYPOINT ["/usr/local/docker-entrypoint.sh"]
# Start PHP-FPM and Nginx servers
CMD /usr/local/php-fpm.sh & nginx -g "daemon off;" -c "/etc/nginx/nginx.conf" & /usr/sbin/sshd -D
CMD /usr/local/php-fpm.sh & nginx -g "daemon off;" -c "/var/www/nginx.conf" & /usr/sbin/sshd -D
11 changes: 11 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ else
echo "File $file_path does not exist."
fi

#copy nginx config
file_path="/etc/nginx/nginx.conf"
dst_path="/var/www/nginx.conf"
if [ -f "$dst_path" ]; then
echo "$dst_path already exist."
else
echo "Creating $dst_path..."
cp "$file_path" "/var/www/"
echo "Nginx file copied successfully."
fi

# loop over "pluggable" content in the source, and if it already exists in the destination, skip it
# https://github.com/docker-library/wordpress/issues/506 ("wp-content" persisted, "akismet" updated, WordPress container restarted/recreated, "akismet" downgraded)
for contentPath in \
Expand Down
1 change: 0 additions & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ http {
fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# Deny all attempts to access hidden files such as .htaccess or .htpasswd
Expand Down
32 changes: 15 additions & 17 deletions wp-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
// (it gets parsed by the upstream wizard in https://github.com/WordPress/WordPress/blob/f27cb65e1ef25d11b535695a660e7282b98eb742/wp-admin/setup-config.php#L356-L392)

// a helper function to lookup "env_FILE", "env", then fallback
if (!function_exists('getenv_docker')) {
if ( !function_exists('getenv_docker') ) {
// https://github.com/docker-library/wordpress/issues/588 (WP-CLI will load this file 2x)
function getenv_docker($env, $default) {
if ($fileEnv = getenv($env . '_FILE')) {
return rtrim(file_get_contents($fileEnv), "\r\n");
function getenv_docker( $env, $default ) {
if ( $fileEnv = getenv( $env . '_FILE') ) {
return rtrim( file_get_contents( $fileEnv ), "\r\n" );
}
else if (($val = getenv($env)) !== false) {
else if ( ( $val = getenv( $env ) ) !== false ) {
return $val;
}
else {
Expand All @@ -44,13 +44,13 @@ function getenv_docker($env, $default) {

// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', getenv_docker('WORDPRESS_DB_NAME', 'test_db') );
define( 'DB_NAME', getenv_docker('WORDPRESS_DB_NAME', '') );

/** Database username */
define( 'DB_USER', getenv_docker('WORDPRESS_DB_USER', 'root') );
define( 'DB_USER', getenv_docker('WORDPRESS_DB_USER', '') );

/** Database password */
define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', '123secret') );
define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', '') );

/**
* Docker image fallback values above are sourced from the official WordPress installation wizard:
Expand All @@ -59,7 +59,7 @@ function getenv_docker($env, $default) {
*/

/** Database hostname */
define( 'DB_HOST', getenv_docker('WORDPRESS_DB_HOST', 'mysql') );
define( 'DB_HOST', getenv_docker('WORDPRESS_DB_HOST', '') );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', getenv_docker('WORDPRESS_DB_CHARSET', 'utf8') );
Expand Down Expand Up @@ -116,9 +116,9 @@ function getenv_docker($env, $default) {
// Check DB connection
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$is_slave = true;
if ($mysqli->connect_errno) {// this is a slave node
if ( $mysqli->connect_errno ) {// this is a slave node
//Disable cron on slave nodes
define('DISABLE_WP_CRON',true);
define( 'DISABLE_WP_CRON' , true );
//Disable WP_AUTO_UPDATE_CORE on slave nodes
define( 'WP_AUTO_UPDATE_CORE', false );
} else {
Expand All @@ -128,16 +128,16 @@ function getenv_docker($env, $default) {

// If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact
// see also https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy
if (!empty($_SERVER['HTTP_HOST']) || $_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
if ( !empty( $_SERVER['HTTP_HOST'] ) || $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ) {
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https' ) !== false ) {
$_SERVER['HTTPS'] = 'on';
} else {
define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/' );
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/' );
}
} else {
// request comming from FDM health check, check if node is slave
if ($is_slave) {
if ( $is_slave ) {
header('HTTP/1.1 500 Internal Server Error');
echo 'Database connection failed';
exit(0);
Expand All @@ -148,9 +148,7 @@ function getenv_docker($env, $default) {
}
}

// (we include this by default because reverse proxying is extremely common in container environments)

if ($configExtra = getenv_docker('WORDPRESS_CONFIG_EXTRA', '')) {
if ( $configExtra = getenv_docker('WORDPRESS_CONFIG_EXTRA', '') ) {
// eval($configExtra);
}

Expand Down

0 comments on commit 52a5316

Please sign in to comment.