无法访问 Live Ubuntu 服务器中的 Laravel 公共文件夹

问题描述 投票:0回答:1

问题: 我无法访问公共文件夹中的所有文件,但是当我在index.php 中时没有问题。

This is my index.php screenshot There is some image that's not loaded, when i inspect element, i get this error: Same result when, i'm manually write url in browser like this, I've already checked in server, the file is exists

我刚刚提供了我的index.php屏幕截图,有一些资产(图像,css,js)未加载,当我检查元素时,我收到404错误。当我在浏览器中手动写入网址时,结果相同,我已经签入服务器,文件存在。

此问题仅发生在实时服务器中,在开发环境中不会发生此问题。所有文件都是相同的,因为我只是将其从本地克隆到我的实时服务器

服务器及项目描述:

  • Ubuntu 22
  • PHP 8
  • 节点JS 18
  • NPM 10
  • 我正在使用 laravel 11

实时服务器中我的 .env 的一些部分:

APP_NAME="Everbright Web Integrated"
APP_ENV=production
APP_KEY=base64:xxx
APP_DEBUG=false
APP_TIMEZONE=UTC
APP_URL=https://192.168.8.210:443

事情已经完成:

  1. php artisan storage:链接 -> 结果失败
  2. 将公用文件夹的权限设置为777 -> 结果失败
  3. 手动检查文件是否存在 -> 结果失败
  4. 将环境更改为 Productionn -> 结果失败

我希望访问公共文件夹中的文件时不会出现 404 错误

/etc/apache2/sites-available/xxx.conf 中适用于此虚拟服务器的 Apache 指令

DocumentRoot /home/public_html/ewi/public
ServerAdmin xxx
SSLEngine on
SSLCertificateFile /etc/apache2/xxx
SSLCertificateKeyFile /etc/apache2/xxx
<Directory /home/public_html/ewi>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
ErrorLog ${APACHE_LOG_DIR}/demo-error.log
CustomLog ${APACHE_LOG_DIR}/demo-access.log combined

enter image description here

这是我的路线文件:

<?php
    
    
use Illuminate\Support\Facades\Auth;

use Illuminate\Support\Facades\Route;
    
    
Route::get('/', function () {
        if (Auth::check()) {
            return view('home', ['kdSupp' => Auth::user()->kdsupp]);
        } else {
            return view('welcome');
        }
    });
    
    
Auth::routes();
    
    
Route::get('/list-supp', [App\Http\Controllers\WebRequestController::class, 'listSupplier']);
    
    
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
    

// Surat Jalan
    
Route::get('/surat-jalan/upload', [App\Http\Controllers\SuratJalanController::class, 'index']);
    
Route::get('/surat-jalan/view', [App\Http\Controllers\SuratJalanController::class, 'lihatSuratJalan']);
    
Route::get('/surat-jalan/detail/{id}', [App\Http\Controllers\SuratJalanController::class, 'lihatDetailSuratJalan']);
    
Route::post('/surat-jalan/upload', [App\Http\Controllers\SuratJalanController::class, 'importExcel']);
    
Route::patch('/surat-jalan/ubah', [App\Http\Controllers\SuratJalanController::class, 'ubahSuratJalan']);
    
Route::patch('/surat-jalan/ubah-item', [App\Http\Controllers\SuratJalanController::class, 'ubahItemSuratJalan']);
    
Route::delete('/surat-jalan/hapus', [App\Http\Controllers\SuratJalanController::class, 'hapusSuratJalan']);
    
Route::delete('/surat-jalan/hapus-item', [App\Http\Controllers\SuratJalanController::class, 'hapusItemSuratJalan']);
    
// End Surat Jalan
    
    

//Invoice
    
Route::get('/invoice/upload', [App\Http\Controllers\InvoiceController::class, 'index']);
    
Route::get('/invoice/view', [App\Http\Controllers\InvoiceController::class, 'lihatInvoice']);
    
Route::get('/invoice/detail/{id}', [App\Http\Controllers\InvoiceController::class, 'lihatDetailInvoice']);
    
Route::post('/invoice/upload', [App\Http\Controllers\InvoiceController::class, 'importExcel']);
    
Route::patch('/invoice/ubah', [App\Http\Controllers\InvoiceController::class, 'ubahInvoice']);
    
Route::patch('/invoice/ubah-harga', [App\Http\Controllers\InvoiceController::class, 'ubahHarga']);
    
Route::delete('/invoice/hapus', [App\Http\Controllers\InvoiceController::class, 'hapusInvoice']);
    
Route::delete('/invoice/hapus-sj', [App\Http\Controllers\InvoiceController::class, 'hapusSuratJalan']);
    
//End Invoice

//Faktur Pajak
    
Route::get('/faktur-pajak/upload', [App\Http\Controllers\FakturPajakController::class, 'index']);
    
Route::get('/faktur-pajak/view', [App\Http\Controllers\FakturPajakController::class, 'lihatFakturPajak']);
    
Route::get('/faktur-pajak/detail/{id}', [App\Http\Controllers\FakturPajakController::class, 'lihatDetailFakturPajak']);
    
Route::post('/faktur-pajak/upload', [App\Http\Controllers\FakturPajakController::class, 'importExcel']);
    
Route::patch('/faktur-pajak/ubah', [App\Http\Controllers\FakturPajakController::class, 'ubahFP']);
    
Route::patch('/faktur-pajak/ubah-invoice', [App\Http\Controllers\FakturPajakController::class, 'ubahInvoice']);
    
Route::delete('/faktur-pajak/hapus', [App\Http\Controllers\FakturPajakController::class, 'hapusFP']);
    
Route::delete('/faktur-pajak/hapus-invoice', [App\Http\Controllers\FakturPajakController::class, 'hapusInvoice']);
    
//End Faktur Pajak
    
    

Route::post('/upload-excel', [App\Http\Controllers\UploadController::class, 'prosesUpload']);
    // Download Route
    Route::get('download/template/{filename}', function ($filename) {
        // Check if file exists in app/storage/file folder
        $file_path = storage_path() . '/file/' . $filename;
        if (file_exists($file_path)) {
            // Send Download
            return Response::download($file_path, $filename, [
                'Content-Length: ' . filesize($file_path)
            ]);
        } else {
            // Error
            exit('Requested file does not exist on our server!');
        }
    })
        ->where('filename', '[A-Za-z0-9\-\_\.]+');
    
php laravel apache ubuntu webmin
1个回答
0
投票

启用mod_rewrite模块:

sudo a2enmod rewrite
sudo systemctl restart apache2

检查 Apache 用户:

打开 Apache 配置文件 /etc/apache2/apache2.conf 或 /etc/httpd/conf/httpd.conf。

将公共目录的所有权更改为www-data

sudo chown -R www-data:www-data /home/public_html/ewi/public

清除缓存

php artisan config:cache
php artisan route:cache
php artisan view:cache
© www.soinside.com 2019 - 2024. All rights reserved.