【发布时间】:2021-06-28 23:38:58
【问题描述】:
嗨,我花了几个小时让我的网站在共享主机上运行,但什么也没发生(本地还可以), 搜索了一些主题并遵循了教程,但无法解决无法加载引导程序和 livewire 组件的问题。
我按照经典步骤将公用文件夹复制到我的子域的根目录,其他文件位于子域路径内的单独文件夹中,如 Laravel 文件夹 我更改了 public/index.php 并且我得到了类似this
你可以看到 livewire 并且引导程序不起作用。
我也尝试让文件夹作为原始文件夹,我的路径是公共的,结果就像this 和一切正常!
css和livewire不起作用的索引路径:
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is maintenance / demo mode via the "down" command we
| will require this file so that any prerendered template can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
require __DIR__.'/../storage/framework/maintenance.php';
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/laravel/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/laravel/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = tap($kernel->handle(
$request = Request::capture()
))->send();
$kernel->terminate($request, $response);
我知道我没有放 /../,因为如果我放那个,我得到错误无法识别路径,可能是因为是子域,并且没有 public_html 文件夹。 是什么导致了这个问题?引导的路径是正确的..
Web.config:
<!--
Rewrites requires Microsoft URL Rewrite Module for IIS
Download: https://www.iis.net/downloads/microsoft/url-rewrite
Debug Help: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules
-->
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
【问题讨论】:
-
为什么要使用共享主机?你甚至有 SSH 访问权限吗?重要的是 Apache 或 Nginx 文档根目录是
LARAVEL_ROOT/public就是这样,然后一切都应该在根目录中,例如app、bootstrap、storage等文件夹... -
因为是 vfm 选项而不是空间有限的昂贵 vps,所以我有 ssh 访问权限,但我现在不知道如何修复它们
-
您使用的是 Apache 还是 Nginx ?您能否在帖子中分享您网站的配置文件?
-
@matiaslauriti 我在 Hostinger 共享主机上,我正在使用 Apache,我在帖子上上传了 htaccess 和 web.config
-
我不知道托管商有什么。如果您使用的是 Apache,您可以共享
/etc/apache2/sites-available上的虚拟主机吗?
标签: laravel hosting shared-hosting