웹 이 Nginx 에 배 치 된 후 정적 파일 로드 가 정상 이 아 닙 니 다 (MIME TYPE 문제)
2209 단어 Django
웹 사 이 트 를 nginx 에 배치 하지 않 기 전에 모든 것 이 정상적으로 실 행 됩 니 다. 웹 사 이 트 를 nginx 에 배치 한 후에 웹 페이지 를 열 수 있 지만 스타일 은 모두 불 러 오지 않 았 습 니 다. 브 라 우 저 에서 F12 키 를 누 르 면 console 에 오류 가 발생 했 습 니 다.
Resource interpreted as Stylesheet but transferred with MIME type text/plain
파일 을 찾 았 음 을 증명 합 니 다. 그러나 분 석 된 형식 이 정확 하지 않 습 니 다. 이 문 제 는 nginx 에 배 치 된 후에 발생 한 것 이기 때문에 nginx 설정 에서 문 제 를 찾 습 니 다.
원인:
연 구 를 통 해 mime. types 라 는 파일 을 도입 해 야 하 는데 MIME TYPES 가 무엇 입 니까?
The Multipurpose Internet Mail Extensions (MIME) type is a standardized way to indicate the nature and format of a document. It is defined and standardized in IETF RFC 6838. The Internet Assigned Numbers Authority (IANA) is the official body responsible to keeping track of all official MIME types, and you can find the most up-to-date and complete list at the Media Types page.
Browsers often use the MIME type (and not the file extension) to determine how it will process a document; it is therefore important that servers are set up correctly to attach the correct MIME type to the header of the response object.
따라서 MIME type 이 있어 야 브 라 우 저가 문 서 를 어떤 방식 으로 처리 해 야 하 는 지 알 수 있 습 니 다. 공식 문 서 를 찾 아 보면 자주 사용 하 는 두 가지 mime type 은 다음 과 같 습 니 다.
Two primary MIME types are important for the role of default types:
text/plain
is the default value for textual files. A textual file should be human-readable and must not contain binary data. application/octet-stream
is the default value for all other cases. An unknown file type should use this type. Browsers pay a particular care when manipulating these files, attempting to safeguard the user to prevent dangerous behaviors. mime type 을 지정 하지 않 으 면 기본적으로 text / plain 으로 처 리 됩 니 다. 즉, 브 라 우 저 는 css 와 js 파일 을 일반 텍스트 로 처리 하기 때문에 스타일 을 제대로 불 러 올 수 없습니다.
해결 방법:
Nginx 설정 파일 에 기본 MIME type 을 지정 합 니 다. 위의 참조 에서 일반적으로 application / ocket - stream 으로 지정 하면 됩 니 다. CentOS 7 에서 설정 파일 / etc / nginx / nginx. conf 를 수정 하고 http {} 에 다음 두 줄 을 추가 합 니 다.
include /etc/nginx/mime.types; default_type application/octet-stream;
nginx 서비스 다시 시작:
service nginx restart
사 이 트 를 다시 불 러 오 면 정상 으로 돌아 올 수 있 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Django 라우팅 계층 URLconf 작용 및 원리 해석URL 구성(URLconf)은 Django가 지원하는 웹 사이트의 디렉토리와 같습니다.그것의 본질은 URL과 이 URL을 호출할 보기 함수 사이의 맵표입니다. 위의 예제에서는 URL의 값을 캡처하고 위치 매개 변수로...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.