我们正在努力使用hgin5mode在nginx web服务器后面设置AngularJS应用程序,对于我们能够实现的大多数部分,页面加载正常,URL映射以及css和通过css引用的任何图像。
然而,所有字体和直接参考图像都无法加载(例如src="/images/myimage.jpg"
)
此问题仅发生在Web服务器上,而不是在开发人员计算机中提供AngularJS应用程序时。
以下是我们的nginx配置的样子
server {
listen 80;
server_name example.com;
keepalive_timeout 60;
client_max_body_size 10M;
root /var/lib/www/dist;
charset utf-8;
location / {
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
root /var/lib/www/dist;
try_files $uri$args $uri$args/ $uri/ /index.html =404;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/lib/app/etc/templates;
}
}
图片和字体未加载,并在控制台中显示以下错误
Resource interpreted as Image but transferred with MIME type text/html: "http://staging.com/images/Er.jpg".
about:1 Resource interpreted as Image but transferred with MIME type text/html: "http://staging.com/images/Ka.jpg".
about:1 Resource interpreted as Font but transferred with MIME type text/html: "http://staging.com/styles/fonts/proximanova/proximanova-regular.woff".
about:1 Resource interpreted as Font but transferred with MIME type text/html: "http://staging.com/styles/fonts/proximanova/proximanova-bold.woff".
about:1 Resource interpreted as Font but transferred with MIME type text/html: "http://staging.com/styles/fonts/proximanova/proximanova-light.woff".
about:1 Resource interpreted as Font but transferred with MIME type text/html: "http://staging.com/styles/fonts/proximanova/proximanova-regular.ttf".
about:1 Resource interpreted as Font but transferred with MIME type text/html: "http://staging.com/styles/fonts/proximanova/proximanova-bold.ttf".
about:1 Resource interpreted as Font but transferred with MIME type text/html: "http://staging.com/styles/fonts/proximanova/proximanova-light.ttf".