매번 똑같은 질문을 계속하는 것 같아서…죄송합니다…ㅠㅠ 여전히 저는 static

 
DongHyeok Lee

매번 똑같은 질문을 계속하는 것 같아서…죄송합니다…ㅠㅠ

여전히 저는 static 폴더 잡는 부분이 너무 힘든 것 같네요 ㅠㅠ

현재 settings.py
STATIC_URL = ‘/static/’
STATIC_ROOT = os.path.join(BASE_DIR, ‘collected_static’)
STATICFILES_DIRS = (os.path.join(‘static’),)

이렇게 잡아두고
메인 html에서
{% load staticfiles %}

이런식으로 불러왔습니다.

로컬에서는 debug=true일 때 잘 나옵니다.

그래서 바로 ubuntu 서버에 nginx+uwsgi로 해당 프로젝트를 올렸습니다.

nginx에서 static 서빙하기 위해서
location /static {
autoindex on;
root /home/ubuntu/first_projects;
}

라고 쓰니,

[Error] Did not parse stylesheet at ‘http;//HOSTIP/static/style.css’ because non CSS MIME types are not allowed in strict mode.

이런식으로 떠버리네요….
(debug가 T/F둘 다 그럽니다….ㅠㅠ)

제가 무슨 바보 같은 짓을 한 걸 까요?ㅠㅠ

  • 권재원

    ngnix 세팅에서는 root 쓰시지 말구 alias를 사용하세요 http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html 여기 참고하시면 됩니다

    Sanghee Lee

    먼저, 장고 셋팅의 STATIC_ROOT와 nginx.conf의 “location /static” 디렉터리 이름이 틀리네요. 참고로 밑에는 제 서버 셋팅입니다.
    # nginx.conf
    location /static/ {
    alias /home/schoolofweb/static/;
    }

    # settings.py
    STATIC_URL = ‘/static/’
    STATIC_ROOT = os.path.join(BASE_DIR, ‘static/’)

    Chinseok Lee

    nginx 설정의 /static/ location 을 collected_static 으로 alias 시키시면 됩니다.

    location /static {
    alias /프로젝트경로절대경로/collected_static;
    }