5. Django - Nginx 연동

2019. 11. 11. 16:34·Python/Django
반응형

참고 : https://victorydntmd.tistory.com/257

 

Nginx 설치

# Nginx 설치

> vi /etc/yum.repos.d/nginx.repo

# Insert this parhase
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1


# Firewall 설정

> yum install nginx

> firewall-cmd --permanent --zone=public --add-service=http
> firewall-cmd --permanent --zone=public --add-service=https

> firewall-cmd --reload


# Nginx 등록 및 시작
> systemctl enable nginx
> systemctl start nginx

http://아이피주소 로 접속확인
[Welcome to Nginx!]

uwsgi 설치

yum install -y gcc

pip install uwsgi

uwsgi 설정 파일

# mkdir /etc/uwsgi/sites
# /etc/uwsgi/sites/django.ini

[uwsgi]
project = django_sample
username = nginx
base = /home

### Django Settings
# base directory
# 프로젝트 경로
chdir = /home/django_sample/django_sample

# python path
# 가상 env python 폴더 혹은 서버 python
home = /usr/local/bin/

# virtualenv path
# 가상 env path
#virtualenv = /home/django_sample/sampleenv

# wsgi.py path
# django 프로젝트 wsgi.py 경로
module = django_sample.wsgi:application

master = true
processes = 1

uid = nginx
socket = /run/uwsgi/django.sock
chown-socket = nginx:nginx
chmod-socket = 660
vacuum = true

#logto = /var/log/uwsgi/djangoTest.log
logto = /home/django_sample.log

 

# vi /etc/systemd/system/uwsgi.service


[Unit]
Description=uWSGI service

[Service]
ExecStartPre=/bin/mkdir -p /run/uwsgi
ExecStartPre=/bin/chown nginx:nginx /run/uwsgi
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target




# systemctl daemon-reload

--emperor

uwsgi는 emperor 모드에서 실행할 수 있습니다.
이 모드에서는 uWSGI 설정 파일의 디렉토리를 감시하고 발견 한 각각에 대한 인스턴스를 생성하게 됩니다.
즉, emperor 모드를 통해 여러 응용 프로그램을 관리 할 수 있습니다.

# /etc/nginx/conf.d/default.conf


server {
    listen       8000;
    server_name  192.168.1.229;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        #root   /usr/share/nginx/html;
        #index  index.html index.htm;
        include uwsgi_params;
        uwsgi_pass unix:/run/uwsgi/django.sock;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

 

# systemctl start uwsgi

# systemctl enable uwsgi
728x90
반응형
저작자표시 (새창열림)
'Python/Django' 카테고리의 다른 글
  • Django demo project (chatting, monggo db, sample)
  • 4. Django 모델 및 관리자
  • 3. Django 뷰 작성 및 라우팅
  • 2. Django 프로젝트 생성
상쾌한기분
상쾌한기분
  • 상쾌한기분
    상쾌한기분
    상쾌한기분
  • 전체
    오늘
    어제
    • 분류 전체보기 (250)
      • Python (44)
        • Python (26)
        • Django (6)
        • Flask (4)
        • Open Source (6)
      • Kotlin & Java (5)
        • Spring (2)
        • 프로젝트 (1)
      • Go (11)
      • Database (24)
        • MySQL (21)
        • Redis (3)
      • Infrastructure (2)
        • CDC (4)
        • Kafka (5)
        • Prometheus (2)
        • Fluentd (11)
        • Docker (1)
        • Airflow (2)
        • VPN (2)
      • IT (25)
        • AI (9)
        • Langchain (8)
        • Web (18)
        • Git (8)
        • 리팩토링 (9)
        • Micro Service Architecture (8)
        • Clean Code (16)
        • Design Pattern (0)
        • 수학 (1)
        • 알고리즘 (14)
      • OS (14)
        • Centos (10)
        • Ubuntu (3)
        • Mac (1)
      • Search Engine (2)
        • ElasticSearch (1)
        • Lucene Solr (1)
      • PHP (2)
        • Laravel (1)
        • Codeigniter (1)
  • 블로그 메뉴

    • Github 방문
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    Langchain
    Golang
    LLM
    fluentd
    go
    performance
    오블완
    티스토리챌린지
    CDC
    http
    파이썬
    docker
    백준
    Kafka
    ollama
    MYSQL
    prompt
    Redis
    python
    git
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
상쾌한기분
5. Django - Nginx 연동
상단으로

티스토리툴바