Setting up WordPress behind a ssl reverse proxy

Setting up docker images

Get the following images

  • mysql:5.7.9 or later
  • wordpress:4.5.2.-apache

MYSQL settings

Memory:
Limited to 128MB

Ports
local port Container port type
32772 3306 tcp

Volumes
External Internal
/docker/mysql/var/lib/mysql /var/lib/mysql

Links
Containername Alias
- -

Enviroment
Variable Value
MYSQL_ROOT_PASSWORD mysql-root-pw

WordPress settings

Memory:
Limited to 128MB

Ports
local port Container port type
8080 80 tcp

Volumes
External Internal
/docker/wordpress/var/www/html /var/www/html

Links
Containername alias
wp_mysql mysql

Enviroment
Variable Value
WORDPRESS_DB_USER root
WORDPRESS_DB_PASSWORD mysql-root-pw

Configure nginx as reverse proxy

 

# HTTPS redirect to wp_backend with variables set to inform 
# WordPress application about revese proxy
server {
   listen 443 ssl;
   server_name wordpress.domain;
   location / {
      proxy_set_header X-Forwarded-Proto https;
      proxy_set_header X-Forwarded-Ssl on;
      proxy_set_header Host $Host;
      proxy_pass http://wp_backend:8080/;
   }

   ssl_certificate /path to/fullchain.pem;
   ssl_certificate_key /path to/privkey.pem;

   add_header Strict-Transport-Security max-age=15768000;
}

# Permanent redirect to HTTPS from HTTP
server {
   listen 80;
   server_name wordpress.domain;
   return 301 https://$host$request_uri;
}

Configure WordPress to use correct links

After running the installation part of WordPress you must configure the URLs used on pages and includes.

Log into WordPress and go to: Settings | General and update the following fields

Backing up WordPress DB

  1. Change your directory to the directory you want to export backup to:
user@linux:~> cd files/blog
user@linux:~/files/blog>

2. Use mysqldump command with your MySQL server name, user name and database name. It prompts you to input password. (For help, try: man mysqldump.)

To backup all database tables
mysqldump --add-drop-table -h mysql_hostserver -u mysql_username -p mysql_databasename
To backup only certain tables from the database
mysqldump --add-drop-table -h mysql_hostserver -u mysql_username -p mysql_databasename mysql_tablename1 mysql_tablename2 mysql_tablename3

Example:

user@linux:~/files/blog> mysqldump --add-drop-table -h db01.example.net -u dbocodex -p wp > blog.bak.sql
Enter password: (type password)

3. Use bzip2 to compress the backup file

user@linux:~/files/blog> bzip2 blog.bak.sql

You can do the same thing that above two commands do in one line:

user@linux:~/files/blog> mysqldump --add-drop-table -h db01.example.net -u dbocodex -p wp | bzip2 -c > blog.bak.sql.bz2
Enter password: (type password)

The bzip2 -c after the | (pipe) means the backup is compressed on the fly, and the > blog.bak.sql.bz2 sends the bzip output to a file named blog.bak.sql.bz2.

Despite bzip2 being able to compress most files more effectively than the older compression algorithms (.Z, .zip, .gz), it isconsiderably slower (compression and decompression). If you have a large database to backup, gzip is a faster option to use.

user@linux:~/files/blog> mysqldump --add-drop-table -h db01.example.net -u dbocodex -p wp | gzip > blog.bak.sql.gz

Don't be such an angerball