nginx,cloudRun@GCP上部署的angular应用加载直达路由时出现问题

n9vozmp4  于 2023-10-17  发布在  Nginx
关注(0)|答案(1)|浏览(141)

我试图在nginx上部署我的angular应用程序作为GCP云运行的容器。该应用程序工作正常,如果我通过主页加载应用程序和导航.但如果我尝试直接加载应用程序路由。它失败,并出现以下mime错误。我已经在nginx中允许了mime.types并添加到nginx.conf文件中。我还添加了下面的位置标记中重写为index.html

runtime.46fb68c434174d9b.js:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
polyfills.938d3d63ac22b057.js:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
main.89919748d2009153.js:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec

location / {
  try_files $uri $uri/ /index.html;
  index index.html index.htm Default.htm;
  add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
  add_header X-Content-Type-Options nosniff;
}
bn31dyow

bn31dyow1#

我能找出问题所在。问题是我在构建时将basehref保持为./,输出为--output-path=/dist/out。我纠正它,它开始工作...

相关问题