我有一个多阶段的Docker镜像,用于我的Angular应用程序,它使用nginx:alpine基础镜像。 我有以下Nginx配置和VHOST设置文件(在Docker容器内部)。
/etc/nginx/nginx.conf
/etc/nginx/conf.d/default.conf
我的项目文件在以下位置:
/usr/share/nginx/html
以下是我的配置: 1. default.conf
server {
listen 0.0.0.0:80;
listen [::]:80;
default_type application/octet-stream;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
client_max_body_size 256M;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /index.html =404;
}
}
2. nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
如您所见,mime.types文件已经被包含了,在给定的路径中也有此文件。
当我运行这个应用程序时,浏览器会显示以下错误信息(针对加载的css和javascript文件):
Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
我在论坛上尝试了许多组合,但都没有成功。如果您有解决方案的提示,请告诉我。
index.html
,在错误信息中解释MIME类型。 - Richard Smith