下面是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没有,但有警告。我错过了什么吗?
1条答案
按热度按时间0aydgbwb1#
你有没有试过把
include /etc/nginx/mime.types;
这一行添加到http作用域中,而不是服务器作用域?https://www.nginx.com/resources/wiki/start/topics/examples/full/