Last active
April 22, 2021 16:01
-
-
Save nerdoc/85e487a2bf1ab76ef10e7063dbc5e944 to your computer and use it in GitHub Desktop.
Install script for Nginx/Dokuwiki on Ubuntu 20.04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
die() { | |
echo "ERROR: $1" | |
exit 1 | |
} | |
[ $(whoami) = "root" ] || die "This script must be run as root" | |
echo "Please go to https://download.dokuwiki.org/, create a download archive, and paste the download link here:" | |
read -p ">" DOWNLOAD_LINK | |
echo -n "Please enter your server FQDN here : " | |
read -p "($HOSTNAME) >" SERVER_NAME | |
if [ ${SERVER_NAME} = "" ]; then | |
SERVER_NAME=$HOSTNAME | |
fi | |
apt install nginx php php-xml || die "Could not install php/nginx" | |
cd /var/www || die "/var/www/ directory does not exist" | |
[ -d dokuwiki ] && die "There is already a /var/www/dokuwiki directory. Please delete it before re-running this script." | |
wget ${DOWNLOAD_LINK} --output-document=/tmp/dokuwiki.tgz | |
tar xzfp /tmp/dokuwiki.tgz || die "Could not extract the dokuwiki archive." | |
echo " | |
server { | |
server_name ${SERVER_NAME}; | |
root /var/www/dokuwiki; | |
index index.php index.html index.html; | |
error_log /var/log/nginx/dokuwiki.error.log; | |
access_log /var/log/nginx/dokuwiki.access.log; | |
# rewrite_log on; | |
# server_tokens off; | |
# add_header X-Content-Type-Options nosniff; | |
# add_header X-XSS-Protection '1; mode=block'; | |
location / { | |
index doku.php; | |
try_files $uri $uri/ @dokuwiki; | |
} | |
location ~ /(data|conf|bin|inc|vendor)/ { | |
deny all; | |
} | |
location ~ ^/lib.*\.(gif|png|ico|jpg)$ { | |
expires 30d; | |
} | |
location ^~ /conf/ { return 403; } | |
location ^~ /data/ { return 403; } | |
location @dokuwiki { | |
rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last; | |
rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last; | |
rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last; | |
rewrite ^/(.*) /doku.php?id=$1&$args last; | |
} | |
location ~ [^/]\.php(/|$) { | |
include snippets/fastcgi-php.conf; | |
# fill in correct php version here. | |
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
# fastcgi_split_path_info ^(.+?\.php)(/.*)$; | |
# if (!-f $document_root$fastcgi_script_name) { | |
# return 404; | |
# } | |
# fastcgi_index index.php; | |
include fastcgi_params; | |
} | |
} | |
" > /etc/nginx/sites-available/${SERVER_NAME}.conf | |
ln -s /etc/nginx/sites_available/${SERVER_NAME}.conf /etc/nginx/sites-enabled/${SERVER_NAME}.conf | |
systemctl enable nginx | |
systemctl start nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment