Skip to content

Commit

Permalink
CREATE: local test uWSGI web server with Nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
phin09 committed Apr 29, 2021
1 parent 1662016 commit d8652e6
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@ my_settings.py
/csv
*.csv
db_uploader.py
static


# Created by https://www.toptal.com/developers/gitignore/api/django,linux,git,python,vim,vscode
Expand Down
13 changes: 10 additions & 3 deletions README.md
Expand Up @@ -3,14 +3,15 @@
### 1. 프로젝트 선정 이유
이 프로젝트의 원본은 2021년 2월, 2주간 진행한 팀프로젝트입니다. [팀프로젝트 Github](https://github.com/phin09/17-1st-StyleWe-backend)
2021년 4월, 혼자 일주일간 리팩토링을 진행하고자 합니다.
2021년 4월, 혼자 일주일간 리팩토링을 진행합니다.
레거시를 읽고 기존 팀코드의 가독성, 효율을 개선하며 Django의 기능을 더 공부하고 싶습니다.

### 2. 리팩토링 목표
- 불분명한 변수명을 변경하고 가독성을 위해 불필요한 변수 삭제.
- 데이터베이스를 건드리지 않고 기존 백엔드 API의 효율을 개선.
- 데이터베이스 구조를 건드리지 않고 기존 백엔드 API의 효율을 개선.
- 대체한 함수는 전과 후의 로직과 성능을 비교.
- API 문서화.
- RDS, EC2 사용.
- unit test 진행.

### 3. 일주일 기록
Expand All @@ -20,8 +21,14 @@
- models.py에 맞게 ERD 수정.
2. 4/24
- [drf-yasg](https://github.com/axnsan12/drf-yasg)를 사용해 API 문서화 시도.
3. 4.25
3. 4/25
- [drf-yasg](https://github.com/axnsan12/drf-yasg)를 사용해 Swagger UI 기반 기존 API 문서화 완료. 엔드포인트 '/swagger'
4. 4/26
- 웹서버 시도 - Nginx, uWSGI 설치
5. 4/27
- 웹서버 시도 - Nginx, uWSGI 연결
6. 4/29
- 로컬에서 Nginx, unix 웹소켓, uWSGI 연결 성공

## Reference
> 이 프로젝트는 스타일쉐어 사이트를 참조하여 학습목적으로 만들었습니다.
Expand Down
35 changes: 35 additions & 0 deletions config/nginx_copy/stylewe_nginx.conf
@@ -0,0 +1,35 @@
# https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html#configure-nginx-for-your-site
# /etc/nginx/sites-available/stylewe_nginx.conf 로 넣어둔 내용.

# the upstream component nginx needs to connect to
upstream django {
server unix:/home/phin09/devel/wecode/style-we/stylewe.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name 0.0.0.0; # substitute your machine's IP address or FQDN
charset utf-8;

# max upload size
client_max_body_size 75M; # adjust to taste

# Django media
# location /media {
# alias /path/to/your/mysite/media; # your Django project's media files - amend as required
# }

location /static {
alias /home/phin09/devel/wecode/style-we/static; # your Django project's static files - amend as required
}

# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/phin09/devel/wecode/style-we/uwsgi_params; # the uwsgi_params file you installed
}
}
2 changes: 2 additions & 0 deletions config/settings.py
@@ -1,3 +1,4 @@
import os
from pathlib import Path

import my_settings
Expand Down Expand Up @@ -109,6 +110,7 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

#REMOVE_APPEND_SLASH_WARNING
Expand Down
20 changes: 0 additions & 20 deletions pull_request_template.md

This file was deleted.

2 changes: 2 additions & 0 deletions requirements.txt
Expand Up @@ -12,6 +12,7 @@ django-countries==7.0
djangorestframework==3.12.4
drf-yasg==1.20.0
flex==6.14.1
gunicorn==20.1.0
idna==2.10
inflection==0.5.1
itypes==1.2.0
Expand All @@ -34,4 +35,5 @@ sqlparse==0.4.1
strict-rfc3339==0.7
uritemplate==3.0.1
urllib3==1.26.4
uWSGI @ file:///home/conda/feedstock_root/build_artifacts/uwsgi_1602758936018/work
validate-email==1.3
6 changes: 6 additions & 0 deletions test.py
@@ -0,0 +1,6 @@
# uwsgi 테스트용
# https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html#basic-test

def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"testtest"] # python3
16 changes: 16 additions & 0 deletions uwsgi_params
@@ -0,0 +1,16 @@
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;

0 comments on commit d8652e6

Please sign in to comment.