티스토리 뷰
[ Nginx 설치 ]
- Yum을 통해 Nginx 설치
$ yum -y install nginx
[ Nginx 설정 ]
- Nginx todo.conf 만들기
$ vi /etc/nginx/conf.d/todo.conf
server {
listen 80;
server_name localhost;
location = /favicon.ico { access_log off; log_not_found off; }
# Django media
location /media {
internal;
gzip_static on;
expires max;
alias /opt/todo/media; # your Django project's media files - amend as required
include /etc/nginx/mime.types;
}
location /static {
gzip_static on;
expires max;
alias /opt/todo/.static_root; # your Django project's static files - amend as required
include /etc/nginx/mime.types;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/opt/todo/socket.sock;
}
}
- Nginx nginx.conf 수정
+ server { ... } 부분 주석처리
$ vi /etc/nginx/conf
# server {
# listen 80 default_server;
# listen [::]:80 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
[ Nginx Service 실행 ]
- Gunicorn Service 실행
- Nginx Service 실행
$ systemctl start gunicorn
$ systemctl start nginx
[ Nginx & Gunicorn & Django 연동 확인 ]
- http://[ Django Project Server IP ]
[ 접근 log 확인 ]
- Nginx Access log를 통해 Nginx & Gunicorn & Django의 정상적인 접근 확인
$ tail -f /var/log/nginx/access.log
192.168.219.1 - - [09/Feb/2020:00:20:33 +0900] "GET / HTTP/1.1" 200 16351 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"
192.168.219.1 - - [09/Feb/2020:00:24:15 +0900] "GET / HTTP/1.1" 200 16351 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36" "-"
- Gunicorn Service 확인을 통해 Nginx & Gunicorn & Django의 정상적인 접근 확인
$ journalctl -f -t gunicorn
-- Logs begin at 토 2020-02-08 22:00:52 KST. --
2월 08 22:20:29 django-01 gunicorn[1655]: [2020-02-08 22:20:29 +0900] [1658] [INFO] Booting worker with pid: 1658
2월 08 22:20:29 django-01 gunicorn[1655]: [2020-02-08 22:20:29 +0900] [1660] [INFO] Booting worker with pid: 1660
2월 08 22:20:29 django-01 gunicorn[1655]: [2020-02-08 22:20:29 +0900] [1661] [INFO] Booting worker with pid: 1661
2월 08 22:20:29 django-01 gunicorn[1655]: [2020-02-08 22:20:29 +0900] [1664] [INFO] Booting worker with pid: 1664
2월 08 22:20:29 django-01 gunicorn[1655]: [2020-02-08 22:20:29 +0900] [1666] [INFO] Booting worker with pid: 1666
2월 08 22:20:29 django-01 gunicorn[1655]: [2020-02-08 22:20:29 +0900] [1668] [INFO] Booting worker with pid: 1668
2월 08 22:20:29 django-01 gunicorn[1655]: [2020-02-08 22:20:29 +0900] [1670] [INFO] Booting worker with pid: 1670
2월 08 22:20:29 django-01 gunicorn[1655]: [2020-02-08 22:20:29 +0900] [1672] [INFO] Booting worker with pid: 1672
2월 09 00:20:33 django-01 gunicorn[1655]: - - [08/Feb/2020:15:20:33 +0000] "GET / HTTP/1.0" 200 16351 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
2월 09 00:24:15 django-01 gunicorn[1655]: - - [08/Feb/2020:15:24:15 +0000] "GET / HTTP/1.0" 200 16351 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
2월 09 00:26:50 django-01 gunicorn[1655]: - - [08/Feb/2020:15:26:50 +0000] "GET / HTTP/1.0" 200 16351 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
'[Web] > Django' 카테고리의 다른 글
[Django] Django Tutorial - Settings.py (0) | 2020.02.13 |
---|---|
[Django] Django Tutorial - VS Code 개발 환경 설정 (0) | 2020.02.09 |
[Django] Django Tutorial - Django & Gunicorn 연동하기 (0) | 2020.02.08 |
[Django] Django Tutorial - Django 설치하기 (0) | 2020.02.02 |
[Django] Django Tutorial - Python 3.x Virtualenv 만들기 (0) | 2020.02.02 |
Comments
최근에 올라온 글