为单页vuejs应用配置虚拟主机的问题

Problem with configuring virtual host for single page vuejs app

我想托管一个具有 vue 路由器的单页 Vuejs 应用程序。我正在使用 apache2 虚拟主机,我已经为网站编写了以下代码。

<VirtualHost *:80>
    ServerAdmin example@email.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/dist

    <Directory /var/www/example.com/dist/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

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

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
    </IfModule>

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

</VirtualHost>

我项目的根目录是/var/www/mydomain.com。现在,当我尝试使用此命令安装让我们加密 ssl 证书时:certbot --apache -d example.com -d www.example.com 它给我一个错误提示:

Error while running apache2ctl configtest.
Action 'configtest' failed.
The Apache error log may have more information.

AH00526: Syntax error on line 22 of /etc/apache2/sites-enabled/example.com.conf:
RewriteBase: only valid in per-directory config files.

我不知道该怎么办。谁能帮帮我?

我像下面这样更改了我的代码,它成功了!

<VirtualHost *:80>
ServerAdmin example@email.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/dist

<Directory /var/www/example.com/dist/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

</Directory>

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

<IfModule mod_dir.c>
    DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>

我将以下代码放入 <Directory /var/www/example.com/dist/> </Directory> 部分,它工作正常。

<IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.html$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.html [L]
 </IfModule>