[Django Install] 9.1 sc제일은행 nginx-django 연결

[Django 설치]


Django는 이미 설치된 것으로 가정하고 진행.

프로젝트명 : sc
프로젝트 디렉토리 : /datanode/datashare/sc

[Django static 파일 마이그레이션]

nginx에서 사용할 static 파일을 만들어 준다.

python manage.py collectstatic (static_root만 영향을 준다.)

STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles/") 에 설정된 staticfiles 디렉토리 하위에 app별 폴더가 만들어진다. (app의 static 폴더의 images, js, css 파일에 변경이 있으면 실행이 필요하다)
MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles') 에 설정된 디렉토리에는 첨부파일이나 업로드 이미지 파일이 만들어진다. (위 명령어와 관련이 없으며, 관리자나 사용자가 업로드한 파일들이 저장된다.)


[uwsgi 설치]

파이썬 가상화 환경에 로그인한 후 실행

pip install uwsgi


[Nginx 설치]

sudo apt-get install nginx

설치 후 자동적으로 Nginx가 Start 된다.

프로세스 시작 : sudo service nginx start
프로세스 종료 : sudo service nginx stop
프로세스 재시작 : sudo service nginx restart
프로세스 상태 : sudo service nginx status

[Nginx - Django 연동]

/datanode/datashare/web/nginx/nginx.conf 파일수정 (아래 내용으로 수정)


# the upstream component nginx needs to connect to

    upstream django {

        server unix:///datanode/datashare/web/sc/sc.sock;

    }


    server {

        listen       1.234.25.132:30002;

        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        # location / {

        #     root   html;

        #     index  index.html index.htm;

        # }


        # Django media

        location /media  {

              alias /home/ubuntu/prefity/mediafiles;

        }


        location /static {

              alias /home/ubuntu/prefity/staticfiles;

        }


        # Finally, send all non-media requests to the Django server.

        location / {

              uwsgi_pass  django;

              include     /datanode/datashare/web/sc/uwsgi_params;

        }



cp /etc/nginx/uwsgi_params /datanode/datashare/web/sc/uwsgi_params

/datanode/datashare/web/sc/sc_uwsgi.ini 파일생성 (아래 내용으로 생성)

# mysite_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /datanode/datashare/web/sc
# Django's wsgi file
module          = sc.wsgi
# the virtualenv (full path)
# home            = /home/ubuntu/.virtualenvs/prefity (가상환경 사용시 지정)

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 3
# the socket (use the full path to be safe
socket          = /datanode/datashare/web/sc/sc.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 666
# clear environment on exit
vacuum          = true

touch-reload = /datanode/datashare/web/sc/settings.py #  설정 변경 시 자동로드

py-autoreload = 1  # 소스코드 변경 시 자동로드


[실행순서]

cd /datanode/datashare/web/sc

uwsgi --ini sc_uwsgi.ini &

nginx start

댓글

댓글 쓰기

이 블로그의 인기 게시물

[Django APP] django-widget-tweaks

[Django App] django-user-agents