Почему не загружаются страницы на сайте laravel?
Делал пробный проект laravel, используя php artisan serve - всё работает. Всё хорошо. Решил после этого перекинуть на apache. И тут понеслись проблемы.
- Почему-то у меня воспринимается только https. То есть проект открывает главную страницу только на hhtps. Даже если я удалю из smarthouse.conf описание 443 порта (тогда вообще работать не будет)
- С главной страницы я никуда не могу перейти. Везде выскакивает ошибка, что такого URL не обнаружено.
smarthouse.conf из sites-available
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin user@localhost
DocumentRoot /var/www/smarthome/public
ServerName smarthome.loc
<Directory /var/www/smarthouse/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin user@localhost
DocumentRoot /var/www/smarthome/public
<Directory /var/www/smarthouse/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ServerName smarthome
ServerAlias smarthome.ru smarthome.com smarthouse smarthouse.com smarthouse.ru smarthome.loc
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
</IfModule>
Команда a2enmode rewrite прописана. В apache2.conf прописан сам модуль.
.htaccess в корневой папке проекта
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond
RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ ./index.php [L]
</IfModule?
.htaccess из папки public
<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>
Файл .env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:keeeyyy=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
Фрагмент из app.php
'url' => env('APP_URL', 'http://localhost'),
'asset_url' => env('ASSET_URL'),
web.php
Route::get('/', function () {
return view('main');
})->name('mainPage');
Route::get('/about', function () {
return view('about');
})->name('aboutPage');
Route::get('/contact', function () {
return view('contact');
})->name('contactPage');
Правка № 1 Изменил для закрытия 443
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin user@localhost
DocumentRoot /var/www/smarthome/public
ServerName smarthome.loc
<Directory /var/www/smarthouse/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
</VirtualHost>
</IfModule>
<VirtualHost *:80>
ServerAdmin user@localhost
DocumentRoot /var/www/smarthome/public
<Directory /var/www/smarthouse/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ServerName smarthome
ServerAlias smarthome.ru smarthome.com smarthouse smarthouse.com smarthouse.ru smarthome.loc
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Источник: Stack Overflow на русском