Django와 nginx를 연동하기 위해서 flup 라이브러리를 설치한다.
$ pip install flup
Django 실행은 다음과 같다.
$ python manage.py runfcgi method=prefork pidfile=PID_FILE host=127.0.0.1 port=8000
nginx.conf 에 다음과 같이 추가한다.
server {
listen 80
server_name localhost;
location /static/ { #static url
autoindex on;
root /static/; #static 파일들이 저장된 디렉토리
}
location / { #사용할 url
#root /usr/share/nginx/html;
#index index.html index.htm;
fastcgi_pass 127.0.0.1:8000;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
}
static url을 설정할 때 /static/으로 해서 파일을 불러오지 못할 경우 앞이나 뒤의 /를 제거하면 된다.
위와 같이 수정한 설정 파일을 다시 읽는다.
$ sudo /etc/init.d/nginx reload