在 Apache 2 上运行 Angular-cli [英] Running Angular-cli on Apache 2

查看:35
本文介绍了在 Apache 2 上运行 Angular-cli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to run Angular 4 on Apache 2 on Fedora 25.

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

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

Produces the dist directory as expected. Next I pointed the Apache to that directory in

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

/etc/httpd/conf/httpd.conf (all the comments have been removed),

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 提供服务

Theses config settings tell Apache to server the index.html at /root/beans3/dist

重启服务器,

$ systemctl restart httpd

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

Navigating to 139.162.199.9 I can see that Apache is running the index.html file in /root/beans/dist

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

However the other files in that directory as not being found. This is strange since they are in the same directory as index.html

/root/beans3/dist/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>

推荐答案

问题在 index.html

the issue is in index.html <base>

请将改为因为您将配置中的 DocumentRoot 设置为该路径.

please change <base href="/root/beans3/dist/"> to <base href="/"> since you are setting the DocumentRoot in your config to that path.

或删除 -bh 并使用 ng build --prod

这篇关于在 Apache 2 上运行 Angular-cli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆