Skip to content

Commit 0a804d4

Browse files
committed
initial commit
0 parents  commit 0a804d4

28 files changed

+3542
-0
lines changed

Dockerfile

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
FROM ubuntu:14.04
2+
3+
MAINTAINER Ian Lintner "[email protected]"
4+
ENV DEBIAN_FRONTEND noninteractive
5+
6+
# Ensure UTF-8
7+
RUN locale-gen en_US.UTF-8
8+
ENV LANG en_US.UTF-8
9+
ENV LC_ALL en_US.UTF-8
10+
11+
#ENV SMTP_HOST smtp.gmail.com
12+
#ENV SMTP_PORT 587
13+
#ENV SMTP_FROMNAME My Name
14+
#ENV SMTP_USERNAME [email protected]
15+
#ENV SMTP_PASSWORD secret
16+
17+
ENV TERM xterm
18+
ENV PHP_OPCACHE enabled
19+
# Update system
20+
RUN apt-get update && apt-get dist-upgrade -y
21+
22+
# Prevent restarts when installing
23+
RUN echo '#!/bin/sh\nexit 101' > /usr/sbin/policy-rc.d && chmod +x /usr/sbin/policy-rc.d
24+
25+
# Basic packages
26+
RUN apt-get -y install php5-fpm php5-mysql php-apc php5-imagick php5-imap php5-mcrypt php5-curl php5-cli php5-gd php5-pgsql php5-sqlite php5-common php-pear curl php5-json php5-redis php5-memcache
27+
RUN apt-get -y install nginx-extras git curl supervisor
28+
RUN apt-get -y install nano
29+
#RUN apt-get -y install msmtp msmtp-mta
30+
31+
RUN php5enmod mcrypt
32+
33+
RUN /usr/bin/curl -sS https://getcomposer.org/installer | /usr/bin/php
34+
RUN /bin/mv composer.phar /usr/local/bin/composer
35+
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
36+
37+
# Install Composer and Drush
38+
RUN /usr/local/bin/composer self-update
39+
RUN /usr/local/bin/composer global require drush/drush:6.*
40+
RUN ln -s /root/.composer/vendor/drush/drush/drush /usr/local/bin/drush
41+
42+
# Prepare directory
43+
RUN mkdir /var/www
44+
RUN usermod -u 1000 www-data
45+
RUN usermod -a -G users www-data
46+
RUN chown -R www-data:www-data /var/www
47+
48+
EXPOSE 80
49+
EXPOSE 443
50+
WORKDIR /var/www
51+
VOLUME ["/var/www/sites/default/files"]
52+
CMD ["/usr/bin/supervisord", "-n"]
53+
54+
# Startup script
55+
# This startup script wll configure nginx
56+
ADD ./startup.sh /opt/startup.sh
57+
RUN chmod +x /opt/startup.sh
58+
59+
#ADD ./mail.sh /opt/mail.sh
60+
#RUN chmod +x /opt/mail.sh
61+
62+
ADD ./cron.sh /opt/cron.sh
63+
RUN chmod +x /opt/cron.sh
64+
65+
# We want it empty
66+
#RUN touch /etc/msmtprc
67+
#RUN chgrp mail /etc/msmtprc
68+
#RUN chmod 660 /etc/msmtprc
69+
#RUN touch /var/log/supervisor/msmtp.log
70+
#RUN chgrp mail /var/log/supervisor/msmtp.log
71+
#RUN chmod 660 /var/log/supervisor/msmtp.log
72+
#RUN adduser www-data mail
73+
74+
#RUN rm /usr/sbin/sendmail
75+
#RUN rm /usr/lib/sendmail
76+
77+
#RUN ln -s /usr/bin/msmtp /usr/sbin/sendmail
78+
#RUN ln -s /usr/bin/msmtp /usr/bin/sendmail
79+
#RUN ln -s /usr/bin/msmtp /usr/lib/sendmail
80+
81+
RUN mkdir -p /var/cache/nginx/microcache
82+
83+
RUN mkdir -p /etc/nginx/ssl
84+
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
85+
86+
87+
### Add configuration files
88+
# Supervisor
89+
ADD ./config/supervisor/supervisord-nginx.conf /etc/supervisor/conf.d/supervisord-nginx.conf
90+
91+
# PHP
92+
ADD ./config/php/www.conf /etc/php5/fpm/pool.d/www.conf
93+
ADD ./config/php/php.ini /etc/php5/fpm/php.ini
94+
95+
# Nginx
96+
ADD ./config/nginx/blacklist.conf /etc/nginx/blacklist.conf
97+
ADD ./config/nginx/drupal.conf /etc/nginx/drupal.conf
98+
ADD ./config/nginx/drupal_upload_progress.conf /etc/nginx/drupal_upload_progress.conf
99+
ADD ./config/nginx/fastcgi.conf /etc/nginx/fastcgi.conf
100+
ADD ./config/nginx/fastcgi_drupal.conf /etc/nginx/fastcgi_drupal.conf
101+
ADD ./config/nginx/fastcgi_microcache_zone.conf /etc/nginx/fastcgi_microcache_zone.conf
102+
ADD ./config/nginx/fastcgi_no_args_drupal.conf /etc/nginx/fastcgi_no_args_drupal.conf
103+
ADD ./config/nginx/map_cache.conf /etc/nginx/map_cache.conf
104+
ADD ./config/nginx/microcache_fcgi.conf /etc/nginx/microcache_fcgi.conf
105+
ADD ./config/nginx/microcache_fcgi_auth.conf /etc/nginx/microcache_fcgi_auth.conf
106+
ADD ./config/nginx/mime.types /etc/nginx/mime.types
107+
ADD ./config/nginx/nginx.conf /etc/nginx/nginx.conf
108+
ADD ./config/nginx/upstream_phpcgi_unix.conf /etc/nginx/upstream_phpcgi_unix.conf
109+
ADD ./config/nginx/map_block_http_methods.conf /etc/nginx/map_block_http_methods.conf
110+
ADD ./config/nginx/map_https_fcgi.conf /etc/nginx/map_https_fcgi.conf
111+
ADD ./config/nginx/nginx_status_allowed_hosts.conf /etc/nginx/nginx_status_allowed_hosts.conf
112+
ADD ./config/nginx/cron_allowed_hosts.conf /etc/nginx/cron_allowed_hosts.conf
113+
ADD ./config/nginx/php_fpm_status_allowed_hosts.conf /etc/nginx/php_fpm_status_allowed_hosts.conf
114+
ADD ./config/nginx/default /etc/nginx/sites-enabled/default
115+

Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CURRENT_DIRECTORY := $(shell pwd)
2+
3+
build:
4+
@docker build --tag=espressodev/nginx-drupal:latest $(CURRENT_DIRECTORY)
5+
6+
build-no-cache:
7+
@docker build --no-cache --tag=espressodev/nginx-drupal:latest $(CURRENT_DIRECTORY)
8+
9+
.PHONY: build
10+

README.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Docker image with Nginx and PHP 5.5.9 optimized for Drupal 7
2+
This image is build using Ubuntu 14.04 with Nginx and PHP 5.5.9 and is optimized to run Drupal 7.
3+
It can run Drupal 6 but most likelly you'll have PHP errors depending on the modules you have installed. In that case is recommended to use the image iiiepe/nginx-drupal6 or iiiepe/apache-drupal6
4+
5+
Includes:
6+
7+
- nginx
8+
- php
9+
- composer
10+
- drush
11+
12+
Important:
13+
14+
- Logs are at /var/log/supervisor so you can map that directory
15+
- Application root directory is /var/www so make sure you map the application there
16+
- Nginx configuration was provided by https://github.com/perusio/drupal-with-nginx but it's modified
17+
18+
## To build
19+
20+
$ make build
21+
22+
or
23+
24+
$ docker build -t yourname/nginx-drupal .
25+
26+
27+
## To run
28+
Nginx will look for files in /var/www so you need to map your application to that directory.
29+
30+
$ docker run -d -p 8000:80 -v application:/var/www yourname/nginx-drupal
31+
32+
If you want to link the container to a MySQL/MariaDB contaier do:
33+
34+
$ docker run -d -p 8000:80 -v application:/var/www my_mysql_container:mysql yourname/nginx-drupal
35+
36+
The startup.sh script will add the environment variables with MYSQL_ to /etc/php5/fpm/pool.d/env.conf so PHP-FPM detects them. If you need to use them you can do:
37+
<?php getenv("SOME_ENV_VARIABLE_THAT_HAS_MYSQL_IN_THE_NAME"); ?>
38+
39+
## Fig
40+
41+
mysql:
42+
image: mysql
43+
expose:
44+
- "3306"
45+
environment:
46+
MYSQL_ROOT_PASSWORD: 123
47+
web:
48+
image: iiiepe/nginx-drupal
49+
volumes:
50+
- application:/var/www
51+
- logs:/var/log/supervisor
52+
ports:
53+
- "80:80"
54+
links:
55+
- "mysql:mysql"
56+
57+
## Running Drush
58+
With Fig this is actually easier and is the recommended way since if you're running Docker without fig, you'll have to link all containers before you run drush.
59+
60+
$ fig run --rm web drush
61+
62+
### License
63+
Released under the MIT License.

config/nginx/blacklist.conf

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#-*- mode: nginx; mode: flyspell-prog; ispell-local-dictionary: "american" -*-
2+
### This file implements a blacklist for certain user agents and
3+
### referrers. It's a first line of defense. It must be included
4+
### inside a http block.
5+
6+
7+
## Add here all user agents that are to be blocked.
8+
map $http_user_agent $bad_bot {
9+
default 0;
10+
~*^Lynx 0; # Let Lynx go through
11+
libwww-perl 1;
12+
~(?i)(httrack|htmlparser|libwww) 1;
13+
}
14+
15+
## Add here all referrers that are to blocked.
16+
map $http_referer $bad_referer {
17+
default 0;
18+
~(?i)(adult|babes|click|diamond|forsale|girl|jewelry|love|nudit|organic|poker|porn|poweroversoftware|sex|teen|webcam|zippo|casino|replica) 1;
19+
}
20+
21+
## Add here all hosts that should be spared any referrer checking.
22+
geo $bad_referer {
23+
127.0.0.1 0;
24+
192.168.1.0/24 0;
25+
}

config/nginx/cron_allowed_hosts.conf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- mode: nginx; mode:autopair; mode: flyspell-prog; ispell-local-dictionary: "american" -*-
2+
### Configuration file for specifying which hosts can invoke Drupal's
3+
### cron. This only applies if you're not using drush to run cron.
4+
5+
geo $not_allowed_cron {
6+
default 1;
7+
## Add your set of hosts.
8+
127.0.0.1 0; # allow the localhost
9+
192.168.1.0/24 0; # allow on an internal network
10+
}

config/nginx/default

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
server {
2+
listen 80 default_server; # IPv4
3+
4+
5+
# listen [fe80::202:b3ff:fe1e:8328]:80 default_server ipv6only=on; # IPv6
6+
server_name _;
7+
listen 443 ssl;
8+
ssl_certificate /etc/nginx/ssl/nginx.crt;
9+
ssl_certificate_key /etc/nginx/ssl/nginx.key;
10+
11+
limit_conn arbeit 32;
12+
13+
14+
## Access and error logs.
15+
access_log /var/log/supervisor/nginx-access.log;
16+
error_log /var/log/supervisor/nginx-error.log;
17+
18+
## See the blacklist.conf file at the parent dir: /etc/nginx.
19+
## Deny access based on the User-Agent header.
20+
if ($bad_bot) {
21+
return 444;
22+
}
23+
## Deny access based on the Referer header.
24+
if ($bad_referer) {
25+
return 444;
26+
}
27+
28+
## Filesystem root of the site and index.
29+
root /var/www/docroot;
30+
index index.php;
31+
fastcgi_keep_conn on; # keep alive to the FCGI upstream
32+
include drupal.conf;
33+
include drupal_upload_progress.conf;
34+
}

0 commit comments

Comments
 (0)