Nginx mime类型错误,如何在Docker容器中设置它们?

a6b3iqyw  于 2023-08-03  发布在  Nginx
关注(0)|答案(1)|浏览(141)

下面是docker-compose.yml

version: "1.0"
services:
  web:
    container_name: webserver
    image: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./frontend:/frontend
    ports:
      - "8001:80"
    environment:
      - NGINX_HOST=someweb.com
      - NGINX_PORT=80

字符串
以下是nginx.conf

user www-data www-data;
worker_processes auto;

events {
    worker_connections 1024;
}

http {
    server {
        listen 80;
        server_name some.server;
        include /etc/nginx/mime.types;

        location / {
            root /frontend;
            index index.html;

            gzip_static on;
        }
    }
}


我在frontend中的静态文件如下:

├── assets
│   ├── index-af7a4a31.css
│   ├── index-ef3b217c.js
│   └── logo-e79ddb16.gif
├── bootstrap.min.css
├── bootstrap.min.js
├── favicon.ico
├── index.html
├── popper.min.js
└── logo.gif


但是我试着进入我得到的网站:

The stylesheet http://192.168.68.112:8001/bootstrap.min.css was not loaded because its MIME type, “text/plain”, is not “text/css”.

The stylesheet http://192.168.68.112:8001/assets/index-af7a4a31.css was not loaded because its MIME type, “text/plain”, is not “text/css”.

The script from “http://192.168.68.112:8001/bootstrap.min.js” was loaded even though its MIME type (“text/plain”) is not a valid JavaScript MIME type.


我希望通过添加include /etc/nginx/mime.types可以解决这个问题,但它没有,然而,当我试图使用浏览器请求网站时,我得到了MIME type错误,我的css没有加载,我的js没有,但有警告。我错过了什么吗?

0aydgbwb

0aydgbwb1#

你有没有试过把include /etc/nginx/mime.types;这一行添加到http作用域中,而不是服务器作用域?https://www.nginx.com/resources/wiki/start/topics/examples/full/

相关问题