전체 글 (256) 썸네일형 리스트형 Django 도메인 설정 후에 CSRF 설정 EC2 등에 Django web application을 등록하고 도메인을 설정한 경우, csrf 문제로 403 forbidden이 뜨는 경우가 있다. CSRF_TRUSTED_ORIGINS = [ "https://mysite.com", ] 위와 같은 방식으로 settings.py에 설정을 추가해줘야 한다. ALLOWED_HOST에서 "*" 모두 허용 했던걸로 해보면, 안먹힌다. ssl 인증을 받아서 http로 접속시 https로 redirect 되는 식으로 nginx를 설정해놨다면, http://mysite.com 으로 등록할 경우에도 403 forbidden 문제가 발생. 꼭 redirect 되어지는 https:// 로 CSRF_TRUSTED_ORIGINS에 추가해야 함 mysite.com 도 안되었음 Nginx: 413 Request Entity Too Large # file size 이미지 파일 등을 올릴 때 Nginx에서 정한 사이즈보다 큰 경우에 나타나는 에러 문구 /etc/nginx/nginx.conf 또는 /etc/nginx/sites-available/default 에서 설정을 바꿔보자 client_max_body_size 50m; 50 메가 바이트까지 파일의 크기를 올릴 수 있게 지정 아래와 같이 특정 loation에 대해 client_max_body_size도 별도로 설정 가능 http { # Global Nginx settings client_max_body_size 50m; # Set the maximum body size for all servers server { listen 80; server_name example.com; # Set the maximum bo.. Linux(ubuntu) 실행 중인 프로세스 죽이기 #netstat # fuser # port # kill Linux Ubuntu 실행중인 프로세스 죽이기 실행중 포트 확인 netstat -tnlp 실행중인 프로세스 포트번호로 죽이기 (ex 8000번 포트) sudo fuser -k 8000/tcp pid번호로 죽이기 1) pid 번호 확인 ps -ef 2) pid 번호로 죽이기 (ex pid 번호: 5345) sudo kill -9 5345 (저는 개인적으로 fuser를 많이 쓰게 되더군요.) isinstance() # check is instance of class # check type # datetime.date check type 예시 isinstance 활용 - datetime.date의 instance인지 확인하는 예시 import datetime updated = row.get('updated') if isinstance(row.get('updated'), datetime.date) else None 기본적인 내용 + 그 외 추가적인 내용은 아래 포스팅 https://taltal-dev-note.tistory.com/8 Nginx SSL 인증 # https # certbot https://hudi.blog/https-with-nginx-and-lets-encrypt/ Nginx static file 403 forbidden error # Nginx Static file을 못잡는 경우 실행환경: AWS EC2 - Ubuntu22.04 문제상황: EC2 환경에서 Nginx로 django의 static file이 읽어와지지 않는 오류를 마주했습니다. static file들이 있는 경로에 접근을 못하는 403 error (permission denied)가 발생 원인 및 해결방안: Nginx와 연결시키려는 WAS의 모든 경로는 +x 실행 권한을 줘야 한다. EC2 첫 생성시 ubuntu 라는 username으로 시작 기본 $HOME 경로 -> /home/ubuntu ls -l /home 명령어로 ubuntu의 실행권한을 보면 다음과 같이 되어있다. /home/ubuntu 의 실행권한 x가 없다. 여기에 권한을 줘야 Nginx가 문제없이 접근 가능 내 django-project의 경로는 /h.. Nginx Django static file 경로 설정하기 실습 운영체제: Linux(Ubuntu) Nginx를 이용해서 Django web app을 배포할시에, static file 들을 경로를 설정해줘야 합니다. STATIC_URL, STATIC_ROOT 를 설정하고 python manage.py collectstatic STATIC_ROOT는 배포용에 쓰이는 static 경로이고 STATIC_DIRS는 개발단계에서 쓰이는 static 경로라 보면 됩니다. 2개를 가각 다르게 설정해줘야 합니다. 예를 들면 다음과 같이 하면 됩니다. STATIC_URL = '/static/' STATICFILES_DIRS = [os.path.join(BASE_DIR, "static"),] STATIC_ROOT = os.path.join(BASE_DIR, "var", "stat.. Django Deployment with Nginx and Gunicorn 1. Nginx 설치, 설정 설치 sudo apt-get update sudo apt-get install nginx 설정 sudo nano /etc/nginx/sites-available/default server { listen 80; server_name your_domain_name.com; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 설정후 nginx 재시작 sudo systemctl restart nginx 2. Gu.. 이전 1 ··· 18 19 20 21 22 23 24 ··· 32 다음