2014-06-20 01:16:38 +00:00
|
|
|
#!/bin/bash
|
2013-09-01 14:24:49 +00:00
|
|
|
# HTTP: Turn on a web server serving static files
|
|
|
|
#################################################
|
|
|
|
|
2014-06-03 11:12:38 +00:00
|
|
|
source setup/functions.sh # load our functions
|
2014-06-20 01:16:38 +00:00
|
|
|
source /etc/mailinabox.conf # load global vars
|
2014-05-01 19:13:00 +00:00
|
|
|
|
2014-10-05 12:40:07 +00:00
|
|
|
# Some Ubuntu images start off with Apache. Remove it since we
|
|
|
|
# will use nginx. Use autoremove to remove any Apache depenencies.
|
|
|
|
if [ -f /usr/sbin/apache2 ]; then
|
|
|
|
echo Removing apache...
|
|
|
|
hide_output apt-get -y purge apache2 apache2-*
|
|
|
|
hide_output apt-get -y --purge autoremove
|
|
|
|
fi
|
|
|
|
|
2014-10-04 21:57:26 +00:00
|
|
|
# Install nginx and a PHP FastCGI daemon.
|
|
|
|
#
|
|
|
|
# Turn off nginx's default website.
|
|
|
|
|
2014-08-12 11:00:54 +00:00
|
|
|
apt_install nginx php5-fpm
|
2013-09-01 14:24:49 +00:00
|
|
|
|
2013-09-07 20:53:25 +00:00
|
|
|
rm -f /etc/nginx/sites-enabled/default
|
|
|
|
|
2014-09-26 22:01:38 +00:00
|
|
|
# Copy in a nginx configuration file for common and best-practices
|
|
|
|
# SSL settings from @konklone. Replace STORAGE_ROOT so it can find
|
|
|
|
# the DH params.
|
|
|
|
sed "s#STORAGE_ROOT#$STORAGE_ROOT#" \
|
|
|
|
conf/nginx-ssl.conf > /etc/nginx/nginx-ssl.conf
|
2013-09-07 20:53:25 +00:00
|
|
|
|
2014-07-07 11:23:31 +00:00
|
|
|
# Fix some nginx defaults.
|
|
|
|
# The server_names_hash_bucket_size seems to prevent long domain names?
|
|
|
|
tools/editconf.py /etc/nginx/nginx.conf -s \
|
|
|
|
server_names_hash_bucket_size="64;"
|
|
|
|
|
2014-10-04 21:57:26 +00:00
|
|
|
# Bump up PHP's max_children to support more concurrent connections
|
2014-09-04 14:40:33 +00:00
|
|
|
tools/editconf.py /etc/php5/fpm/pool.d/www.conf -c ';' \
|
|
|
|
pm.max_children=8
|
|
|
|
|
2014-06-20 01:16:38 +00:00
|
|
|
# Other nginx settings will be configured by the management service
|
|
|
|
# since it depends on what domains we're serving, which we don't know
|
|
|
|
# until mail accounts have been created.
|
|
|
|
|
2014-11-18 16:32:37 +00:00
|
|
|
# Create the iOS/OS X Mobile Configuration file which is exposed via the
|
2014-11-14 13:49:01 +00:00
|
|
|
# nginx configuration at /mailinabox-mobileconfig.
|
|
|
|
mkdir -p /var/lib/mailinabox
|
|
|
|
chmod a+rx /var/lib/mailinabox
|
|
|
|
cat conf/ios-profile.xml \
|
|
|
|
| sed "s/PRIMARY_HOSTNAME/$PRIMARY_HOSTNAME/" \
|
|
|
|
| sed "s/UUID1/$(cat /proc/sys/kernel/random/uuid)/" \
|
|
|
|
| sed "s/UUID2/$(cat /proc/sys/kernel/random/uuid)/" \
|
|
|
|
| sed "s/UUID3/$(cat /proc/sys/kernel/random/uuid)/" \
|
|
|
|
| sed "s/UUID4/$(cat /proc/sys/kernel/random/uuid)/" \
|
|
|
|
> /var/lib/mailinabox/mobileconfig.xml
|
|
|
|
chmod a+r /var/lib/mailinabox/mobileconfig.xml
|
|
|
|
|
2015-01-31 21:33:18 +00:00
|
|
|
# Create the Mozilla Auto-configuration file which is exposed via the
|
|
|
|
# nginx configuration at /.well-known/autoconfig/mail/config-v1.1.xml.
|
|
|
|
# The format of the file is documented at:
|
|
|
|
# https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
|
|
|
|
# and https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Autoconfiguration/FileFormat/HowTo.
|
|
|
|
cat conf/mozilla-autoconfig.xml \
|
|
|
|
| sed "s/PRIMARY_HOSTNAME/$PRIMARY_HOSTNAME/" \
|
|
|
|
> /var/lib/mailinabox/mozilla-autoconfig.xml
|
|
|
|
chmod a+r /var/lib/mailinabox/mozilla-autoconfig.xml
|
|
|
|
|
2013-09-08 09:55:58 +00:00
|
|
|
# make a default homepage
|
2014-10-04 21:57:26 +00:00
|
|
|
if [ -d $STORAGE_ROOT/www/static ]; then mv $STORAGE_ROOT/www/static $STORAGE_ROOT/www/default; fi # migration #NODOC
|
2014-06-20 01:16:38 +00:00
|
|
|
mkdir -p $STORAGE_ROOT/www/default
|
2014-06-23 19:43:19 +00:00
|
|
|
if [ ! -f $STORAGE_ROOT/www/default/index.html ]; then
|
2014-06-20 01:16:38 +00:00
|
|
|
cp conf/www_default.html $STORAGE_ROOT/www/default/index.html
|
|
|
|
fi
|
2014-06-23 10:53:09 +00:00
|
|
|
chown -R $STORAGE_USER $STORAGE_ROOT/www
|
2013-09-07 20:53:25 +00:00
|
|
|
|
2014-10-04 21:57:26 +00:00
|
|
|
# We previously installed a custom init script to start the PHP FastCGI daemon. #NODOC
|
|
|
|
# Remove it now that we're using php5-fpm. #NODOC
|
2014-08-12 11:00:54 +00:00
|
|
|
if [ -L /etc/init.d/php-fastcgi ]; then
|
2014-10-04 21:57:26 +00:00
|
|
|
echo "Removing /etc/init.d/php-fastcgi, php5-cgi..." #NODOC
|
|
|
|
rm -f /etc/init.d/php-fastcgi #NODOC
|
|
|
|
hide_output update-rc.d php-fastcgi remove #NODOC
|
|
|
|
apt-get -y purge php5-cgi #NODOC
|
2014-08-12 11:00:54 +00:00
|
|
|
fi
|
2013-09-01 14:24:49 +00:00
|
|
|
|
2015-06-14 18:56:20 +00:00
|
|
|
# Don't expose the php version
|
|
|
|
tools/editconf.py /etc/nginx/fastcgi_params \
|
|
|
|
"fastcgi_param PHP_VALUE \"expose_php"="Off\";"
|
|
|
|
|
2014-10-04 21:57:26 +00:00
|
|
|
# Remove obsoleted scripts. #NODOC
|
|
|
|
# exchange-autodiscover is now handled by Z-Push. #NODOC
|
2014-10-07 20:30:36 +00:00
|
|
|
for f in webfinger exchange-autodiscover; do #NODOC
|
2014-10-04 21:57:26 +00:00
|
|
|
rm -f /usr/local/bin/mailinabox-$f.php #NODOC
|
|
|
|
done #NODOC
|
2014-08-19 11:50:00 +00:00
|
|
|
|
2014-03-17 01:46:47 +00:00
|
|
|
# Start services.
|
2014-07-16 13:06:45 +00:00
|
|
|
restart_service nginx
|
2014-08-12 11:00:54 +00:00
|
|
|
restart_service php5-fpm
|
2013-09-01 14:24:49 +00:00
|
|
|
|
2014-03-17 01:46:47 +00:00
|
|
|
# Open ports.
|
2014-05-01 19:35:18 +00:00
|
|
|
ufw_allow http
|
|
|
|
ufw_allow https
|
2013-09-01 14:24:49 +00:00
|
|
|
|