티스토리 뷰

INTRO

Raspi : server

- Python : 3.7.3

- django : 3.2

 

macOS : local-dev

- Python : 3.9.4

- django : 3.2

 

 

local-dev : macOS

1. 가상환경

가상환경 생성 및 실행

~/.virtualenvs/ $ venv pyERP

~/.virtualenvs/ $ cd pyERP

~/.virtualenvs/pyERP $ source bin/activate

(pyERP)$ 

 

2. django 설치 및 django-project 생성

(pyERP)$ pip install --upgrade pip

(pyERP)$ pip install django

(pyERP)$ django-admin.py startproject config

(pyERP)$ mv config testerp

(pyERP)$ cd testerp

(pyERP)testerp$ tree

.

├── config

│   ├── __init__.py

│   ├── asgi.py

│   ├── settings.py

│   ├── urls.py

│   └── wsgi.py

└── manage.py

 

(pyERP)testerp$ nano config/settings.py

ALLOWED_HOSTS = ['localhost']

LANGUAGE_CODE = 'ko'

TIME_ZONE = 'Asia/Seoul'

 

(pyERP)testerp $ .manage.py migrate

(pyERP)testerp $ .manage.py runserver

 

(pyERP)testerp$ tree

.

├── config

│   ├── __init__.py

│   ├── __pycache__

│   │   ├── __init__.cpython-39.pyc

│   │   ├── settings.cpython-39.pyc

│   │   ├── urls.cpython-39.pyc

│   │   └── wsgi.cpython-39.pyc

│   ├── asgi.py

│   ├── settings.py

│   ├── urls.py

│   └── wsgi.py

├── db.sqlite3

└── manage.py

 

django 구동 확인

browser : localhost:8000

우측 상단 Django 3.2 확인

 

 

3. git push

[macOS](pyERP)testerp$ touch .gitignore 

.DS_Store
db.sqlite3
*.pyc
__pycache__/ 

git push 참고 : (macOS)[python][django][RaspberryPi] ERP platform - git , 2. GitHub push : macOS to GitHub repository

 

 

 

 

server : Raspi

4. git pull

Raspi 가상환경과 django 설치는 위의 1,2번 항목과 동일하나 django는 설치만 하고 project 생성은 하지 않음

 

[Raspi](pyERP)$ mkdir testerp

[Raspi](pyERP)$ cd testerp

[Raspi](pyERP)testerp$

 

git pull 참고 : (macOS)[python][django][RaspberryPi] ERP platform - git , 3. GitHub pull : GitHub repository to RaspberryPi

 

[Raspi](pyERP)testerp$ tree

.

├── config

│   ├── asgi.py

│   ├── __init__.py

│   ├── settings.py

│   ├── urls.py

│   └── wsgi.py

└── manage.py

 

[Raspi](pyERP)testerp$ nano config/settings.py

ALLOWED_HOSTS = ['[YourIP]']

[Raspi](pyERP)testerp$ ./manage.py migrate

 

 

5. server test : unix socket 연결

nginx 설치 및 setting 참고 : (Raspbian)[Raspberry Pi] EMP([E]nginx + MariaDB + PHP ) 설치 , 1. nginx 설치 및 확인

 

unix socket 연결 설정 : django project nginx.conf 생성 및 수정

nginx(webserver) <-> unix socket <-> wsgi <-> django

 

[Raspi](pyERP)testerp$ touch uwsgi_params

[Raspi](pyERP)testerp$ nano uwsgi_params

uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param  REQUEST_METHOD     $request_method;
uwsgi_param  CONTENT_TYPE       $content_type;
uwsgi_param  CONTENT_LENGTH     $content_length;

uwsgi_param  REQUEST_URI        $request_uri;
uwsgi_param  PATH_INFO          $document_uri;
uwsgi_param  DOCUMENT_ROOT      $document_root;
uwsgi_param  SERVER_PROTOCOL    $server_protocol;
uwsgi_param  REQUEST_SCHEME     $scheme;
uwsgi_param  HTTPS              $https if_not_empty;

uwsgi_param  REMOTE_ADDR        $remote_addr;
uwsgi_param  REMOTE_PORT        $remote_port;
uwsgi_param  SERVER_PORT        $server_port;
uwsgi_param  SERVER_NAME        $server_name;

 

[Raspi](pyERP)testerp$ touch testerp_nginx.conf

[Raspi](pyERP)testerp$ nano testerp_nginx.conf

## testerp_nginx.conf

# upstream(proxy) setting
upstream django {
    server unix:///home/[YourRaspiID]/.virtualenvs/pyERP/testerp/testerp.sock;
}

# configuration of the server
server {
    # the port your site will be served on
    listen      xxxx[YourPort];

    # the domain name it will serve for
    server_name 192.xxx.xxx.xxx[YourIP];
    charset     utf-8;

    # max upload size :
    client_max_body_size 75M;

    location /media  {
    	alias /home/[YourRaspiID]/.virtualenvs/pyERP/testerp/media;
    }
    
    location /static {
        alias /home/[YourRaspiID]/.virtualenvs/pyERP/testerp/static;
    }

    # Finally, send all non-media requests to the Django server.
	location / {
        uwsgi_pass  django;
        include     /home/[YourRaspiID]/.virtualenvs/pyERP/testerp/uwsgi_params;
    }
}

 

[Raspi](pyERP)testerp$ uwsgi --socket testerp.sock --module config.wsgi --chmod-socket=666

server django 구동 확인

browser : YourIP:XXXX

우측 상단 Django 3.1 확인

 

 

6. server test : testerp.ini 연결

[Raspi](pyERP)testerp$ touch testerp.ini

[Raspi](pyERP)testerp$ nano testerp.ini

[uwsgi]

# django-related settings
# the base directory (full path)
chdir         = /home/[YourRaspiID]/.virtualenvs/pyERP/testerp/
# django’s wigs file (just module name)
module        = config.wsgi
# the virtualenv (full path)
home          = /home/[YourRaspiID]/.virtualenvs/pyERP/

# process-related settings
# master
master        = true
# maximum number of worker processes
processes = 2
# the socket (use the full path to be safe)
socket        = /home/[YourRaspiID]/.virtualenvs/pyERP/testerp/testerp.sock
# … with appropriate permissions - may be need
chmod-socket  = 666
# clear environment on exit
vacuum        = true

 

[Raspi](pyERP)testerp$ uwsgi --ini testerp.ini

server django 구동 확인

browser : YourIP:XXXX

우측 상단 Django 3.2 확인

 

 

[Raspi](pyERP)testerp$ tree

.

├── config

│   ├── asgi.py

│   ├── __init__.py

│   ├── __pycache__

│   │   ├── __init__.cpython-37.pyc

│   │   ├── settings.cpython-37.pyc

│   │   ├── urls.cpython-37.pyc

│   │   └── wsgi.cpython-37.pyc

│   ├── settings.py

│   ├── urls.py

│   └── wsgi.py

├── db.sqlite3

├── manage.py

├── testerp.ini

├── testerp_nginx.conf

└── uwsgi_params

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함