在Apache 2上部署Angular 6应用程序

时间:2018-10-10 09:02:11

标签: angular apache2

我有一个Angular 6应用程序,需要在Apache2上进行部署。 我在/var/www/html/project文件夹中有代码。运行ng build --prod命令,它在dist/project下创建了一个名为/var/www/html/project的文件夹

/etc/apache2/sites-available下创建虚拟主机并启用该站点并重新加载apache2

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName testsite.com
    DocumentRoot /var/www/html/project/dist/project/

    <Directory /var/www/html/project/dist/project/>
            Options -MultiViews
            RewriteEngine on

            # Don't rewrite files or directories
            RewriteCond %{REQUEST_FILENAME} -f [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^ - [L]

            # Rewrite everything else to index.html
            # to allow html5 state links
            RewriteRule . /index.html [L]
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

如果我访问testsite.com,它将显示空白页。

index.html

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Project</title>
<base href="http://testsite.com">
<meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Montserrat:300,700" rel="stylesheet">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <link rel="stylesheet" href="styles.8e98a03e860d2ebfdf70.css"
</head>
<body>
  <app-root></app-root>
   <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
   <script type="text/javascript" src="runtime.a66f828dca56eeb90e02.js"></script><script type="text/javascript" src="polyfills.2f4a59095805af02bd79.js"></script><script type="text/javascript" src="main.430ebc5e8a6533f9924f.js"></script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

能否请您检查“ / var / www / html / project / dist / project /”是否正确并包含index.html?

还要检查此文件夹的权限