restore grub from live ubuntu

sudo mount /dev/sda1 /mnt

sudo mount –bind /dev /mnt/dev &&
sudo mount –bind /dev/pts /mnt/dev/pts &&
sudo mount –bind /proc /mnt/proc &&
sudo mount –bind /sys /mnt/sys

sudo chroot /mnt

grub-install /dev/sda
grub-install –recheck /dev/sda
update-grub

set up youtrack on ubuntu 16.10

sudo apt-get update
sudo apt-get install openjdk-8-jre
sudo apt-get install nginx
sudo adduser youtrack --disabled-password
sudo mkdir -p /usr/local/youtrack
sudo chown youtrack.youtrack /usr/local/youtrack
sudo nano /etc/init.d/youtrack
#! /bin/sh

export HOME=/home/youtrack

NAME=youtrack
SCRIPT=/usr/local/$NAME/$NAME.sh

d_start() {
 su youtrack -l -c "$SCRIPT start"
}

d_stop() {
 su youtrack -l -c "$SCRIPT stop"
}

case "$1" in
 start)
 echo "Starting $NAME..."
 d_start
 ;;
 stop)
 echo "Stopping $NAME..."
 d_stop
 ;;
 restart|force-reload)
 echo "Restarting $NAME..."
 d_stop
 d_start
 ;;
 *)
 echo "Usage: sudo service youtrack {start|stop|restart}" >&2
 exit 1
 ;;
esac

exit 0



sudo chmod +x /etc/init.d/youtrack
sudo /usr/sbin/update-rc.d youtrack defaults
sudo nano /usr/local/youtrack/youtrack.sh
#! /bin/sh

export HOME=/home/youtrack

NAME=youtrack
PORT=8080
USR=/usr/local/$NAME
JAR=$USR/`ls -Lt $USR/*.jar | grep -o “$NAME-[^/]*.jar” | head -1`
LOG=$USR/$NAME-$PORT.log
PID=$USR/$NAME-$PORT.pid

d_start() {
if [ -f $PID ]; then
PID_VALUE=`cat $PID`
if [ ! -z “$PID_VALUE” ]; then
PID_VALUE=`ps ax | grep $PID_VALUE | grep -v grep | awk ‘{print $1}’`
if [ ! -z “$PID_VALUE” ]; then
exit 1;
fi
fi
fi

PREV_DIR=`pwd`
cd $USR
exec java -Xmx1g -XX:MaxPermSize=250m -Djava.awt.headless=true -Djava.security.egd=/dev/zrandom -Djetbrains.youtrack.disableBrowser=true -jar $JAR $PORT >> $LOG 2>&1 &
echo $! > $PID
cd $PREV_DIR
}

d_stop() {
if [ -f $PID ]; then
PID_VALUE=`cat $PID`
if [ ! -z “$PID_VALUE” ]; then
PID_VALUE=`ps ax | grep $PID_VALUE | grep -v grep | awk ‘{print $1}’`
if [ ! -z “$PID_VALUE” ]; then
kill $PID_VALUE
WAIT_TIME=0
while [ `ps ax | grep $PID_VALUE | grep -v grep | wc -l` -ne 0 -a “$WAIT_TIME” -lt 2 ]
do
sleep 1
WAIT_TIME=$(expr $WAIT_TIME + 1)
done
if [ `ps ax | grep $PID_VALUE | grep -v grep | wc -l` -ne 0 ]; then
WAIT_TIME=0
while [ `ps ax | grep $PID_VALUE | grep -v grep | wc -l` -ne 0 -a “$WAIT_TIME” -lt 15 ]
do
sleep 1
WAIT_TIME=$(expr $WAIT_TIME + 1)
done
echo
fi
if [ `ps ax | grep $PID_VALUE | grep -v grep | wc -l` -ne 0 ]; then
kill -9 $PID_VALUE
fi
fi
fi
rm -f $PID
fi
}

case “$1” in
start)
d_start
;;
stop)
d_stop
;;
*)
echo “Usage: $0 {start|stop|restart}” >&2
exit 1
;;
esac

exit 0

sudo chmod +x /usr/local/youtrack/youtrack.sh
sudo service youtrack start
sudo nano /etc/nginx/sites-available/youtrack
server {
 listen 80;

 server_name track.site.tk;

 location / {
 proxy_pass http://localhost:8080;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header Host $http_host;
 }


Set up dokuwiki on ubuntu 16.04

sudo apt-get update
sudo apt-get install nginx
sudo service nginx start
sudo apt-get install php-fpm php-gd php7.0-xml


edit:/etc/php/7.0/fpm/php.ini
with cgi.fix_pathinfo=0

sudo service php7.0-fpm restart

content of /etc/nginx/site-available/wiki


server {    listen  80;
    root /usr/share/nginx/html;    
    index index.php index.html index.htm;
    server_name wiki.wikihost.tk;
    location / {        try_files $uri $uri/ /index.html;    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;    location = /50x.html {        root /usr/share/nginx/html;    }
    location ~ \.php$ {        try_files $uri =404;        fastcgi_pass unix:/run/php/php7.0-fpm.sock;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;        include fastcgi_params;    }
    location ~ /\.ht {        deny all;    }
    location ~ /(data|conf|bin|inc)/ {        deny all;    }
location = / {
 return 301 http://$host/wiki/doku.php;
}
}



Test php:
sudo sh -c 'echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php'

open in browser
server_domain_or_IP_address/info.php

Install dokuwiki
cd ~
wget http://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz

This will download a tarball into your current directory. Extract the directory structure by typing:

tar xzvf dokuwiki-stable.tgz

We can now delete the tarball by typing:

rm dokuwiki-stable.tgz

Let’s change the name of the directory to whatever path we’d like to access our wiki from. We will use wiki for this guide:

mv doku* wiki

We should move our directory into our web root. This will allow us to access our server by typing our domain followed by /wiki. Move the directory now:

sudo mv wiki /usr/share/nginx/www/

Before we continue, we need to do some additional security steps, or the installer will complain that it cannot access certain areas. Change to the directory you just moved:

cd /usr/share/nginx/www/wiki

The web process needs to have certain access to some files and directories within the wiki structure.

sudo chown -R www-data data
sudo chown www-data lib/plugins/
sudo chown www-data conf

Now, we are ready to install DokuWiki through the web browser using an installer script.

In your browser, go to your domain or IP address followed by the wiki sub directory and install.php:

server_domain_or_IP_address/wiki/install.php
 

 

Simple setup postgres db for django

sudo apt-get update
sudo apt-get install python-pip python-dev libpq-dev postgresql postgresql-contrib
sudo su – postgres
psql
CREATE DATABASE uweb;
CREATE USER django WITH PASSWORD ‘django’;
ALTER ROLE django SET client_encoding TO ‘utf8’;
ALTER ROLE django SET default_transaction_isolation TO ‘read committed’;
ALTER ROLE django SET timezone TO ‘UTC’;
GRANT ALL PRIVILEGES ON DATABASE uweb TO django;

How to block specific user agents on nginx web server

To configure user-agent block list, open the nginx configuration file of your website, where the server section is defined. This file can be found in different places depending on your nginx setup or Linux distribution (e.g., /etc/nginx/nginx.conf, /etc/nginx/sites-enabled/<your-site>, /usr/local/nginx/conf/nginx.conf, /etc/nginx/conf.d/<your-site>).

location / {
if ($http_user_agent ~* (ahrefs|megaindex|majestic|mj12) ) {
return 403;
}

You can test it:

wget –user-agent “malicious bot” http://<nginx-ip-address&gt;