nginx + ionic3每条路线均返回index.html

时间:2018-08-16 22:50:46

标签: nginx ionic-framework ionic3

我正在尝试在nginx上部署ionic3 pwa

我有以下nginx.conf,我已从在线示例中将它们修补在一起(完整的nginx新手)

# /etc/nginx/nginx.conf
user nginx;
events {}
http {
  include /etc/nginx/mime.types;
  server {
    # serve client
    listen 80;
    index index.html index.htm;

    location /my-project {

    root /usr/src/app/www;

      # cache
      expires -1;
      add_header Pragma "no-cache";
      add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";

      # ionic routing rewrite
      try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;
    }
  }
}

我可以看到在localhost / my-project上正在提供index.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <script data-ionic="inject">
    (function(w){var i=w.Ionic=w.Ionic||{};i.version='3.9.2';i.angular='5.2.11';i.staticDir='build/';})(window);
  </script>
  <meta charset="UTF-8">
  <title>Permis Animalier Inspecteur Mobile</title>
  <base href="/permis-animalier-inspecteur-mobile/"/>
  <meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">
  <link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
  <link href="assets/css/font-awesome.min.css" rel="stylesheet"/>
  <link href="assets/fonts/vdm.css" rel="stylesheet"/>
  <link rel="manifest" href="manifest.json">
  <meta name="theme-color" content="#4e8ef7">

  <!-- add to homescreen for ios -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">

  <!-- cordova.js required for cordova apps (remove if not needed) -->
  <script src="cordova.js"></script>

  <!-- un-comment this code to enable service worker
  <script>
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('service-worker.js')
        .then(() => console.log('service worker installed'))
        .catch(err => console.error('Error', err));
    }
  </script>-->

  <link href="build/main.css" rel="stylesheet">

</head>
<body>

  <!-- Ionic's root component and where the app will load -->
  <ion-app></ion-app>

  <!-- The polyfills js is generated during the build process -->
  <script src="build/polyfills.js"></script>

  <!-- The vendor js is generated during the build process
       It contains all of the dependencies in node_modules -->
  <script src="build/vendor.js"></script>

  <!-- The main bundle js is generated during the build process -->
  <script src="build/main.js"></script>

</body>
</html>

但是,我还可以在Chrome网络标签中看到,当浏览器尝试加载其中一个资源(例如“ build / main.css”)时,nginx会使用index.html的内容进行响应。我在做什么错了?

0 个答案:

没有答案