Skip to content

Commit 38bff6e

Browse files
committed
Merge branch 'refs/heads/add-wp-ffpc'
2 parents 7017703 + e03a600 commit 38bff6e

File tree

5 files changed

+113
-104
lines changed

5 files changed

+113
-104
lines changed

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ RUN ln -sf /bin/true /sbin/initctl
1010
RUN mkdir /var/run/sshd
1111

1212
# Basic Requirements
13-
RUN apt-get -y install mysql-server mysql-client nginx php5-fpm php5-mysql php-apc pwgen python-setuptools curl git unzip openssh-server openssl
13+
RUN apt-get -y install memcached mysql-server mysql-client nginx php5-fpm php5-mysql php-apc pwgen python-setuptools curl git unzip openssh-server openssl
1414

1515
# Wordpress Requirements
16-
RUN apt-get -y install php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
16+
RUN apt-get -y install php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-memcached php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
1717

1818
# mysql config
1919
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
@@ -24,7 +24,6 @@ RUN sed -i -e"s/keepalive_timeout 2/keepalive_timeout 2;\n\tclient_max_body_size
2424
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
2525

2626
# php-fpm config
27-
RUN sed -i -e "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" /etc/php5/fpm/php.ini
2827
RUN sed -i -e "s/upload_max_filesize\s*=\s*2M/upload_max_filesize = 100M/g" /etc/php5/fpm/php.ini
2928
RUN sed -i -e "s/post_max_size\s*=\s*8M/post_max_size = 100M/g" /etc/php5/fpm/php.ini
3029
RUN sed -i -e "s/;daemonize\s*=\s*yes/daemonize = no/g" /etc/php5/fpm/php-fpm.conf
@@ -51,7 +50,7 @@ RUN mv /usr/share/nginx/www/5* /usr/share/nginx/wordpress
5150
RUN rm -rf /usr/share/nginx/www
5251
RUN mv /usr/share/nginx/wordpress /usr/share/nginx/www
5352
RUN chown -R wordpress:www-data /usr/share/nginx/www
54-
RUN chmod -R 777 /usr/share/nginx/www/wp-content
53+
RUN chmod -R 775 /usr/share/nginx/www
5554

5655
# Wordpress Initialization and Startup Script
5756
ADD ./start.sh /start.sh

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# docker-wordpress-nginx-ssh
22

3-
A Dockerfile that installs the latest wordpress, nginx, php-apc, php-fpm and openssh.
3+
A Dockerfile that installs the latest wordpress, nginx, php-apc, php-fpm and openssh.
4+
Now with memcached caching straight from NGiNX!
45

56
This is a modified fork from [eugeneware](https://github.com/eugeneware/docker-wordpress-nginx). All credits should go to him.
67

@@ -30,6 +31,9 @@ You can the visit the following URL in a browser on your host machine to get sta
3031

3132
http://127.0.0.1:<port>
3233

34+
To enable memcached caching straight from NGiNX, goto WP-FFPC settings page and press the save button. Thats it.
35+
36+
3337
To get the SSH user `wordpress`'s password so you can login and edit files, check the top of the docker container logs for it.
3438

3539
$ docker logs <container-id>

nginx-site.conf

Lines changed: 95 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,22 @@
1-
# You may add here your
2-
# server {
3-
# ...
4-
# }
5-
# statements for each of your virtual hosts to this file
6-
7-
##
8-
# You should look at the following URL's in order to grasp a solid understanding
9-
# of Nginx configuration files in order to fully unleash the power of Nginx.
10-
# http://wiki.nginx.org/Pitfalls
11-
# http://wiki.nginx.org/QuickStart
12-
# http://wiki.nginx.org/Configuration
13-
#
14-
# Generally, you will want to move this file somewhere, and start with a clean
15-
# file but keep this around for reference. Or just disable in sites-enabled.
16-
#
17-
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
18-
##
19-
201
server {
212
listen 80; ## listen for ipv4; this line is default and implied
223
listen [::]:80 default ipv6only=on; ## listen for ipv6
234

5+
charset UTF-8;
246
root /usr/share/nginx/www;
257
index index.php index.html index.htm;
268

27-
# Make site accessible from http://localhost/
289
server_name localhost;
2910

3011
location / {
31-
# First attempt to serve request as file, then
32-
# as directory, then fall back to index.html
33-
try_files $uri $uri/ /index.php?q=$uri&$args;
34-
# Uncomment to enable naxsi on this location
35-
# include /etc/nginx/naxsi.rules
12+
try_files $uri $uri/ @memcached;
3613
}
3714

38-
location /doc/ {
39-
alias /usr/share/doc/;
40-
autoindex on;
41-
allow 127.0.0.1;
42-
allow ::1;
43-
deny all;
15+
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
16+
expires 24h;
17+
log_not_found off;
4418
}
4519

46-
# Only for nginx-naxsi : process denied requests
47-
#location /RequestDenied {
48-
# For example, return an error code
49-
#return 418;
50-
#}
51-
52-
#error_page 404 /404.html;
53-
5420
# redirect server error pages to the static page /50x.html
5521
#
5622
error_page 500 502 503 504 /50x.html;
@@ -60,63 +26,98 @@ server {
6026

6127
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
6228
#
63-
location ~ \.php$ {
64-
try_files $uri =404;
65-
fastcgi_split_path_info ^(.+\.php)(/.+)$;
66-
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
67-
68-
# With php5-cgi alone:
29+
location ~ (\.php) {
30+
try_files $uri =404;
31+
fastcgi_index index.php;
32+
fastcgi_connect_timeout 10;
33+
fastcgi_send_timeout 180;
34+
fastcgi_read_timeout 180;
35+
fastcgi_buffer_size 512k;
36+
fastcgi_buffers 4 256k;
37+
fastcgi_busy_buffers_size 512k;
38+
fastcgi_temp_file_write_size 512k;
39+
fastcgi_intercept_errors on;
40+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
41+
fastcgi_keep_conn on;
42+
43+
fastcgi_param QUERY_STRING $query_string;
44+
fastcgi_param REQUEST_METHOD $request_method;
45+
fastcgi_param CONTENT_TYPE $content_type;
46+
fastcgi_param CONTENT_LENGTH $content_length;
47+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
48+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
49+
fastcgi_param REQUEST_URI $request_uri;
50+
fastcgi_param DOCUMENT_URI $document_uri;
51+
fastcgi_param DOCUMENT_ROOT $document_root;
52+
fastcgi_param SERVER_PROTOCOL $server_protocol;
53+
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
54+
fastcgi_param SERVER_SOFTWARE nginx;
55+
fastcgi_param REMOTE_ADDR $remote_addr;
56+
fastcgi_param REMOTE_PORT $remote_port;
57+
fastcgi_param SERVER_ADDR $server_addr;
58+
fastcgi_param SERVER_PORT $server_port;
59+
fastcgi_param SERVER_NAME $server_name;
60+
fastcgi_param PATH_INFO $fastcgi_path_info;
61+
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
62+
fastcgi_param REDIRECT_STATUS 200;
63+
64+
# uncomment these for HTTPS usage
65+
#fastcgi_param HTTPS $https if_not_empty;
66+
#fastcgi_param SSL_PROTOCOL $ssl_protocol if_not_empty;
67+
#fastcgi_param SSL_CIPHER $ssl_cipher if_not_empty;
68+
#fastcgi_param SSL_SESSION_ID $ssl_session_id if_not_empty;
69+
#fastcgi_param SSL_CLIENT_VERIFY $ssl_client_verify if_not_empty;
70+
6971
fastcgi_pass 127.0.0.1:9000;
70-
# With php5-fpm:
71-
# fastcgi_pass unix:/var/run/php5-fpm.sock;
72-
fastcgi_index index.php;
73-
include fastcgi_params;
7472
}
7573

76-
# deny access to .htaccess files, if Apache's document root
77-
# concurs with nginx's one
78-
#
79-
#location ~ /\.ht {
80-
# deny all;
81-
#}
82-
}
74+
# try to get result from memcached
75+
location @memcached {
76+
default_type text/html;
77+
set $memcached_key data-$scheme://$host$request_uri;
78+
set $memcached_request 1;
79+
80+
# exceptions
81+
# avoid cache serve of POST requests
82+
if ($request_method = POST ) {
83+
set $memcached_request 0;
84+
}
85+
86+
# avoid cache serve of wp-admin-like pages, starting with "wp-"
87+
if ( $uri ~ "/wp-" ) {
88+
set $memcached_request 0;
89+
}
8390

91+
# avoid cache serve of any URL with query strings
92+
if ( $args ) {
93+
set $memcached_request 0;
94+
}
95+
96+
97+
if ($http_cookie ~* "comment_author_|wordpressuser_|wp-postpass_|wordpress_logged_in_" ) {
98+
set $memcached_request 0;
99+
}
100+
101+
102+
103+
if ( $memcached_request = 1) {
104+
add_header X-Cache-Engine "WP-FFPC with memcache via nginx";
105+
memcached_pass memcached-servers;
106+
error_page 404 = @rewrites;
107+
}
108+
109+
if ( $memcached_request = 0) {
110+
rewrite ^ /index.php last;
111+
}
112+
}
113+
114+
location @rewrites {
115+
add_header X-Cache-Engine "No cache";
116+
rewrite ^ /index.php last;
117+
}
118+
119+
}
84120

85-
# another virtual host using mix of IP-, name-, and port-based configuration
86-
#
87-
#server {
88-
# listen 8000;
89-
# listen somename:8080;
90-
# server_name somename alias another.alias;
91-
# root html;
92-
# index index.html index.htm;
93-
#
94-
# location / {
95-
# try_files $uri $uri/ /index.html;
96-
# }
97-
#}
98-
99-
100-
# HTTPS server
101-
#
102-
#server {
103-
# listen 443;
104-
# server_name localhost;
105-
#
106-
# root html;
107-
# index index.html index.htm;
108-
#
109-
# ssl on;
110-
# ssl_certificate cert.pem;
111-
# ssl_certificate_key cert.key;
112-
#
113-
# ssl_session_timeout 5m;
114-
#
115-
# ssl_protocols SSLv3 TLSv1;
116-
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
117-
# ssl_prefer_server_ciphers on;
118-
#
119-
# location / {
120-
# try_files $uri $uri/ /index.html;
121-
# }
122-
#}
121+
upstream memcached-servers {
122+
server 127.0.0.1:11211;
123+
}

start.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,21 @@ if [ ! -f /usr/share/nginx/www/wp-config.php ]; then
3333
# Download nginx helper plugin
3434
curl -O `curl -i -s http://wordpress.org/plugins/nginx-helper/ | egrep -o "http://downloads.wordpress.org/plugin/[^']+"`
3535
unzip nginx-helper.*.zip -d /usr/share/nginx/www/wp-content/plugins
36-
chown -R wordpress:wordpress /usr/share/nginx/www/wp-content/plugins/nginx-helper
36+
37+
curl -O `curl -i -s http://wordpress.org/plugins/wp-ffpc/ | egrep -o "http://downloads.wordpress.org/plugin/[^']+"`
38+
unzip wp-ffpc.*.zip -d /usr/share/nginx/www/wp-content/plugins
39+
chown -R wordpress:www-data /usr/share/nginx/www/wp-content/plugins
40+
41+
sed -i -e $"s/define('WP_DEBUG', false);/define('WP_DEBUG', false);\ndefine('WP_CACHE', true);\ndefine('FS_METHOD', 'direct');/" /usr/share/nginx/www/wp-config.php
42+
3743

3844
# Activate nginx plugin and set up pretty permalink structure once logged in
3945
cat << ENDL >> /usr/share/nginx/www/wp-config.php
4046
\$plugins = get_option( 'active_plugins' );
4147
if ( count( \$plugins ) === 0 ) {
4248
require_once(ABSPATH .'/wp-admin/includes/plugin.php');
4349
\$wp_rewrite->set_permalink_structure( '/%postname%/' );
44-
\$pluginsToActivate = array( 'nginx-helper/nginx-helper.php' );
50+
\$pluginsToActivate = array( 'nginx-helper/nginx-helper.php' , 'wp-ffpc/wp-ffpc.php');
4551
foreach ( \$pluginsToActivate as \$plugin ) {
4652
if ( !in_array( \$plugin, \$plugins ) ) {
4753
activate_plugin( '/usr/share/nginx/www/wp-content/plugins/' . \$plugin );
@@ -52,12 +58,11 @@ ENDL
5258

5359
chown wordpress:www-data /usr/share/nginx/www/wp-config.php
5460

55-
echo "define('FS_METHOD', 'direct');" >> /usr/share/nginx/www/wp-config.php
56-
5761
mysqladmin -u root password $MYSQL_PASSWORD
5862
mysql -uroot -p$MYSQL_PASSWORD -e "CREATE DATABASE wordpress; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY '$WORDPRESS_PASSWORD'; FLUSH PRIVILEGES;"
5963
killall mysqld
6064
fi
6165

6266
# start all the services
67+
service memcached start
6368
/usr/local/bin/supervisord -n

supervisord.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ command=/usr/bin/mysqld_safe
3030
command=/usr/sbin/nginx
3131

3232
[program:ssh]
33-
command=/usr/sbin/sshd -D
33+
command=/usr/sbin/sshd -D

0 commit comments

Comments
 (0)