将Angular应用程序部署到Apache服务器子域

时间:2020-08-31 19:54:33

标签: angular apache .htaccess subdomain

我正在尝试将Angular 9应用程序部署到子域级别的Apache服务器,但是遇到了麻烦。我不知道如何配置服务器和/或.htaccess文件,以使ngapp.domain.nl服务于Angular index.html文件。

到目前为止已采取的步骤:

  • 我使用ng build --prod构建我的Angular应用,生成了一个分发文件夹(dist / ngapp /)
  • 我使用主机提供商的控制面板创建了一个名为“ ngapp”的子域。这样就创建了一个子域文件夹。该文件夹位于root / subdomains / ngapp。我将/ ngapp /分发文件夹中包含的所有内容放入其中。查看文件夹结构here的图像。
  • 我按照Angular's documentation中的说明配置了.htaccess,并将其与分发文件一起放在/ ngapp /中。请参见下面的代码。
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html

.htaccess代码没有为子域配置,但是我不知道如何更改此代码以使其适合。我也不知道是否将.htaccess文件放在正确的文件夹中。

我也不知道我的DNS设置是否正确。

子域行为不变

当我访问子域ngapp.domain.nl时,它将显示一个默认页面(由我的托管服务提供商创建),其中指出了该子域已被占用。不过,它会为我放置在域之前的每个子域执行此操作。

任何帮助将不胜感激:)

编辑:添加了指向images of folder structure

的链接

1 个答案:

答案 0 :(得分:0)

修复:删除了/ ngapp /子域文件夹中的自动生成的index.php。

此index.php已加载,而不是我的index.html。 index.php加载了默认的提供程序页面。其他所有设置都正确。