가상환경 설정

$ cd /my/working/dir

$ virtualenv -p python3 env35

$ cd env35

$ mkdir run

$ source bin/activate

$ pip install django gunicorn

$ django-admin startproject testproject

$ cd testproject

$ django-admin startapp testapp


디렉토리 구조

/my/working/dir


`-- env35
    |-- bin
    |  
    |-- include
    |   `-- python3.5m -> /usr/include/python3.5m
    |-- lib
    |   `-- python3.5
    |-- testproject
    |   |-- media
    |   |-- testproject
    |   |-- static
    |   |-- templates
    |   `-- testapp
    `-- run



gunicorn systemd 등록

$ sudo mkdir /run/gunicorn

$ sudo chown youurUserName.yourGroup /run/gunicorn

# sudo vi /etc/systemd/system/gunicorn.service

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
PIDFile=/run/gunicorn/pid
User=youurUserName
Group=yourGroup
WorkingDirectory=/my/working/dir/env35/testproject
ExecStart=/my/working/dir/env35/bin/gunicorn \
        --pid /run/gunicorn/pid \
        --workers 2 \
        --bind unix:/run/gunicorn/gunicorn.sock \
        testproject.wsgi:application

ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target


gunicorn 서비스 시작

$ sudo systemctrl enable gunicorn.service

$ sudo systemctl start gunicorn.service



# 가상환경 설정

$ virtualenv -p python3 env35

$ cd envDjango

$ mkdir run

$ source bin/activate

$ pip install django gunicorn

$ django-admin startproject testproject

$ cd testproject

$ django 작업

$ cat << EOF > gunicorn_cfg.py
daemon=True
bind='unix:/your/dir/env35/run/gunicorn.sock'
workers=3
EOF

$ gunicorn -c gunicorn_cfg.py testproject.wsgi:application

$ sudo -i

# apt install nginx

# cd /etc/nginx/sites-available/

# cat << EOF > testproject_conf
server {
        listen 80;
        server_name    ${YOUR_SERVER_NAME};
        root        /usr/share/nginx/html;

        location = /favicon.ico { access_log off; log_not_found off; }

        location /static {
                root    root ${YOUR_PROJECT_DIR};
        }

        location / {
                include proxy_params;
                proxy_pass http://unix:/your/dir/env35/run/gunicorn.sock;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
}
EOF

# cd ../sites-enabled/

# ln -s ../sites-available/testproject_conf

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

# nginx -s reload



아래에 링크에 자세한 설명

http://dveamer.github.io/backend/PythonWAS.html

현재 Django LTS 버전인 1.4.x 버전 기반용 소스이다.


단 책 뒷(feed)부분은 되지 않는다.


장고를 다운로드 받을때 장고 사이트를 가서 Download --> Django 1.4.X(LTS) 를 다운로드 받아야 한다.


버전이 틀리면 제대로 되지 않을 가능성 100% 이니 꼭 버전을 맞춰주자..



System Requirements
    python 2.7.x
    django 1.4.x

HOW TO RUN
    ./manage.py runserver

DB USER INFOMATION.
    id : test
    password : 11112222






django_bookmarks_1.4.x.7z


+ Recent posts