首页 > 解决方案 > 在 Apache Centos 中使用 Laravel API 反应应用程序部署

问题描述

我在 Laravel 中有一个带有连接 API 的反应 js 应用程序。在 localhost 中一切正常。当我试图在我的 apache 服务器中托管这个应用程序时,我遇到了一个问题。

试图实现以下配置:

  1. 我的反应应用程序域是www.example.com
  2. 我的 Laravel 应用程序域是www.example.com/api

对于上述 URL 设置

  1. 文档根文件夹:/var/www/html
  2. 反应文件夹:/var/www/html/react/build
  3. laravel 文件夹:/var/www/html/app/

我的虚拟主机配置是

<VirtualHost *:443>
    # Client React application
    DocumentRoot "/var/www/html/react/build"
    ServerName example.com
    SSLEngine on
    
    # Server Laravel 7 API application
    Alias /api /var/www/html/app/public/
    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
    # Rewrite all requests in /api to server index.php
    <Location /api>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ /api/index.php [L]
    </Location>
    <Directory "/var/www/html/app/public/">
            AllowOverride All
            Options Indexes FollowSymLinks
    </Directory>
</VirtualHost>
<virtualhost *:80>
        DocumentRoot /var/www/html
</virtualhost>

在 /var/www/html/.htaccess 中创建 .htaccess

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

我收到类似“在此服务器上找不到请求的 URL”之类的错误。

请帮我。我在这个配置中做错了什么。相同的配置适用于角度。

标签: reactjslaravelapachedeploymenthttpd.conf

解决方案


推荐阅读