Ubuntu16.04 前置作業

sudo apt-get update
sudo apt-get install python-pip
sudo pip install django==1.9.2
sudo apt-get install python-pip python-dev libpq-dev postgresql postgresql-contrib nginx
sudo apt-get install python-lxml
sudo apt-get install libfreetype6-dev libxft-dev  libjpeg62  libjpeg-dev
sudo pip install XlsxWriter
sudo pip install python-docx
sudo pip install Pillow
sudo apt-get build-dep python-psycopg2
sudo pip install psycopg2 
sudo pip install dj-static

Step1:下載專案

cd /var/www
git clone http://github.com/

Step2:設定資料庫

sudo su - postgres
psql
CREATE DATABASE scratch;
CREATE USER scratch WITH PASSWORD '1234';
GRANT ALL PRIVILEGES ON DATABASE scratch TO scratch;
\q
exit
sudo python manage.py migrate
sudo python manage.py createsuperuser
填入資料:admin, koma@mail.nksh.tp.edu.tw, 密碼:pump2246
sudo python manage.py runserver 0.0.0.0:8000
測試網站:http://server_domain_or_IP:8000

Step3:Deploy網站

sudo pip install uwsgi
sudo mkdir -p /etc/uwsgi/sites
sudo nano /etc/uwsgi/sites/scratch.ini
------------------------------------Start
[uwsgi]
project = scratch
base = /var/www/scratch
chdir = /var/www/scratch
module = scratch.wsgi:application
master = true
processes = 5
socket = 127.0.0.1:8001
chmod-socket = 664
vacuum = true
------------------------------------End
sudo nano /etc/systemd/system/uwsgi.service
------------------------------------Start
[Unit]
Description=uWSGI Emperor service

[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /var/run/uwsgi; chown www-data:www-data /var/run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target
------------------------------------End
sudo nano /etc/nginx/sites-available/scratch
------------------------------------Start
server {
    listen 80;
    server_name 127.0.0.1;
    access_log   /var/log/nginx/ccess.log;
    error_log    /var/log/nginx/error.log;
    location = /biconcave {
         return  404;
    }
    location  /static/ {
        root  /var/www/scratch;
    }
    location  /media/ {
        root  /var/www/scratch;                                                                                                   
    }
    location  / {
        uwsgi_pass      127.0.0.1:8001;
        include         /var/www/scratch/uwsgi_params;
        uwsgi_param     SCRIPT_NAME '';
    }
}
-------------------------------------End
sudo ln -s /etc/nginx/sites-available/scratch /etc/nginx/sites-enabled
sudo service nginx configtest
sudo systemctl daemon-reload
sudo systemctl start uwsgi
sudo service nginx start