0

我正在尝试在 Fedora 25 上的 Apache 2 上运行 Angular 4。

$ ng build --prod --bh /root/beans3/dist/

按预期生成 dist 目录。接下来,我将 Apache 指向该目录

/etc/httpd/conf/httpd.conf(所有注释已被删除),

ServerRoot "/etc/httpd"
Listen 139.162.199.9:80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@qqiresources.com
ServerName www.qqiresources.com:80

<Directory />
    AllowOverride none
    Require all granted
</Directory>

DocumentRoot "/root/beans3/dist"

<Directory "/root/beans3">
    AllowOverride All
    Require all granted
</Directory>

<Directory "/root/beans3/dist">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"
LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on

这些配置设置告诉 Apache 在 /root/beans3/dist 服务 index.html

重新启动服务器,

$ systemctl restart httpd

导航到 139.162.199.9 我可以看到 Apache 正在 /root/beans/dist 中运行 index.html 文件

但是,该目录中的其他文件未找到。这很奇怪,因为它们与 index.html 位于同一目录中

在此处输入图像描述

/root/beans3/dist/index.html

<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>Beans3</title>
  <base href="/root/beans3/dist/">
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <title></title>
  <meta name="description" content="">
  <!--<meta name="viewport" content="width=device-width, initial-scale=1"> -->
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

  <!-- <link rel="apple-touch-icon" href="apple-touch-icon.png"> -->
  <!-- Place favicon.ico in the root directory -->

  <!-- <link rel="stylesheet" href="css/normalize.css"> -->
  <!--&lt;!&ndash; Latest compiled and minified CSS &ndash;&gt;-->
  <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> -->
  <!-- <link rel="stylesheet" href="css/main.css"> -->

  <!-- <script src="js/vendor/modernizr-2.8.3.min.js"></script> -->

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="styles.604a57bc7d4c0f84e447.bundle.css" rel="stylesheet"/></head>

<body>
  <script>
    window.__theme = 'bs4';
  </script>
  <app-root>Loading...boo ya!</app-root>
  <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
  <script>
    // window.jQuery || document.write('<script src="js/vendor/jquery-1.12.0.min.js"><\/script>')
  </script>
  <!-- <script src="js/plugins.js"></script> -->
  <!-- <script src="js/main.js"></script> -->
  <script type="text/javascript">
  </script>
  <!-- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>-->
  <!-- <script async src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDNjfWKTRj_IlQ6nPTSXDeKKM7yoEnauNI&callback=getLocation"></script> -->

<script type="text/javascript" src="inline.df954263324e7c133385.bundle.js"></script><script type="text/javascript" src="polyfills.a3e056f914d9748ff431.bundle.js"></script><script type="text/javascript" src="vendor.244ceb2ee1e4bb317079.bundle.js"></script><script type="text/javascript" src="main.47083d1d3073f3856af7.bundle.js"></script></body>

</html>
4

1 回答 1

1

问题出在 index.html 中<base>

请更改<base href="/root/beans3/dist/">为,<base href="/"> 因为您将DocumentRoot配置中的设置设置为该路径。

或删除-bh <path>并使用ng build --prod

于 2017-04-11T15:39:39.390 回答