Nginx는 MIME 유형 오류로 인해 CSS 파일을 제공할 수 없습니다.

Nginx는 MIME 유형 오류로 인해 CSS 파일을 제공할 수 없습니다.

내 설정:

django webapp용 nginx/gunicorn 설정입니다.

내 nginx 구성 파일은 다음과 같습니다.

worker_processes 1;

user ubuntu nogroup; # for systems with a "nogroup"
# user nobody nobody; # for systems with "nobody" as a group instead

# Feel free to change all paths to suit your needs here, of course
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;

events {
  worker_connections 1024; # increase if you have lots of clients
  accept_mutex off; # "on" if nginx worker_processes > 1
  use epoll; # enable for Linux 2.6+
  # use kqueue; # enable for FreeBSD, OSX
}

http {

  # fallback in case we can't determine a type
  default_type application/octet-stream;

  # click tracking!
  access_log /tmp/nginx.access.log combined;

  # you generally want to serve static files with nginx since neither
  # Unicorn nor Rainbows! is optimized for it at the moment
  sendfile off;

  tcp_nopush off; # off may be better for *some* Comet/long-poll stuff
  tcp_nodelay off; # on may be better for some Comet/long-poll stuff


  # this can be any application server, not just Unicorn/Rainbows!
  upstream app_server {

    # for UNIX domain socket setups:
    server localhost:8080;

  }

  server {
    listen 8000;

#    client_max_body_size 4G;
    server_name _;

    proxy_connect_timeout 75s;
    proxy_send_timeout 75s;
    proxy_read_timeout 75s;

    expires -1;
    location /static {
        autoindex on;
        alias /home/ubuntu/mira_website/manageDb/static/;
    }


    location / {

      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

      proxy_set_header Host $http_host;

      proxy_redirect off;

      proxy_buffering off;

      proxy_pass http://app_server;

    }

    # Error pages
    error_page 500 502 503 504 /500.html;
    location = /500.html {
      root /path/to/app/current/public;
    }
  }
}

내가 겪고 있는 오류

브라우저에서 오류가 발생합니다. 다음은 다음과 같습니다.

/static/rest_framework_swagger/css/highlight.default.css was not loaded because its MIME type, "application/octet-stream", is not "text/css".

흥미로운 점은 .js파일이 성공적으로 제공된다는 것입니다. 한 가지 더 주목해야 할 점은 .js.css파일이 모두 django에 의해 생성되었다는 것입니다 python manage.py collectstatic.

/static/rest_framework_swagger/css/highlight.default.css또 다른 흥미로운 점은 URL에 직접 입력하면 다운로드할 파일이 제공된다는 것입니다.

답변1

바보 나. include /etc/nginx/mime.types구성 파일을 넣는 것을 잊어버렸습니다 . 그래서 블록에 넣었 location /static {}더니 이제 작동합니다.

관련 정보