ubuntu
我在服务器上运行 laravel 项目apache2
,当有人下载任何发票/装运标签时都会出现以下错误。
我访问的网址是https://staging.myweb.com
禁止
您无权访问此资源。Apache/2.4.52 (Ubuntu) 服务器位于 staging.myweb.com 端口 443
我在 apache error.log 文件中发现的错误是
[2024 年 2 月 3 日星期六 11:41:30.589613] [autoindex:error] [pid 895124] AH01276:无法提供目录 /var/www/html/public/:未找到匹配的 DirectoryIndex(index.php、index.html),并且 Options 指令禁止服务器生成的目录索引
这是我的虚拟主机文件
000-默认.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
DirectoryIndex index.php index.html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
DirectoryIndex index.php index.html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
DirectoryIndex index.php index.html
</Directory>
<Directory /var/www/html/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
DirectoryIndex index.php index.html
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =staging.myweb.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
DocumentRoot /var/www/html/public
DirectoryIndex index.php index.html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
DirectoryIndex index.php index.html
</Directory>
<Directory /var/www/html/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
DirectoryIndex index.php index.html
</Directory>
CacheQuickHandler on
CacheLock on
CacheLockPath /tmp/mod_cache-lock
CacheLockMaxAge 5
CacheIgnoreHeaders Set-Cookie
CacheEnable disk /
CacheHeader on
CacheDefaultExpire 800
CacheMaxExpire 64000
CacheIgnoreNoLastMod On
ExpiresActive on
ExpiresDefault A300
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/staging.myweb.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/staging.myweb.com/privkey.pem
</VirtualHost>
</IfModule>
我添加了下面的代码以便在这些 VH 文件中进行测试
<Directory /var/www/html/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
DirectoryIndex index.php index.html
</Directory>
和 htaccess 文件
根
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Rewrite to public folder
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/$1 [L]
# Rewrite to index.php
RewriteCond %{REQUEST_URI} !^/public/index\.php
RewriteRule ^(/)?$ /public/index.php [L]
</IfModule>
公用文件夹
<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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
我甚至尝试过改变所有权,www-data
但没有成功。
编辑 如果我打开浏览器并点击禁用缓存,那么网站就开始正常工作
编辑-5二月
正如我已经提到的,它在根文件夹中,laravel
所以没有。而“公共文件夹”与index.php
index.php
这个。
编辑 - 2 月 7 日
将 Apache 日志从 更改为 后,warn
日志debug
如下
[2024 年 2 月 7 日星期三 09:47:56.760745] [socache_shmcb:debug] [pid 3362] mod_socache_shmcb.c(862):AH00847:插入发生在 idx=1,数据=(214:246) [2024 年 2 月 7 日星期三 09:47:56.760750] [socache_shmcb:debug] [pid 3362] mod_socache_shmcb.c(865):AH00848:插入完成,子缓存:idx_pos/idx_used=0/2,data_pos/data_used=0/427 [2024 年 2 月 7 日星期三 09:47:56.760755] [socache_shmcb:debug] [pid 3362] mod_socache_shmcb.c(530): AH00834: 成功离开 socache_shmcb_store [2024 年 2 月 7 日星期三 09:47:56.760844] [socache_shmcb:debug] [pid 3362] mod_socache_shmcb.c(508): AH00831: socache_shmcb_store (0x7c -> subcache 28) [2024 年 2 月 7 日星期三 09:47:56.760853] [socache_shmcb:debug] [pid 3362] mod_socache_shmcb.c(862): AH00847: 插入发生在 idx=0、data=(0:32) [2024 年 2 月 7 日星期三 09:47:56.760858] [socache_shmcb:debug] [pid 3362] mod_socache_shmcb.c(865):AH00848:插入完成,子缓存:idx_pos/idx_used=0/1,data_pos/data_used=0/213 [2024 年 2 月 7 日星期三 09:47:56.760863] [socache_shmcb:debug] [pid 3362] mod_socache_shmcb.c(530):AH00834:成功离开 socache_shmcb_store [2024 年 2 月 7 日星期三 09:47:57.014726] [cache:debug] [pid 3371] mod_cache.c(1349):[客户端] AH00769:缓存:缓存 urlhttps://staging.myweb.com:443/index.php? 对于请求 /index.php,referer: https://staging.myweb.com/admin/sales/shipments/view/10[2024 年 2 月 7 日星期三 09:47:57.014744] [cache:debug] [pid 3371] mod_cache.c(1356):[客户端] AH00770:缓存:删除 CACHE_REMOVE_URL 过滤器。,引荐来源: https://staging.myweb.com/admin/sales/shipments/view/10[2024 年 2 月 7 日星期三 09:47:57.353481] [cache_disk:debug] [pid 3371] mod_cache_disk.c(1361):[客户端] AH00737:commit_entity:URL 的标头和正文https://staging.myweb.com:443/index.php? 已缓存。,引用者:https://staging.myweb.com/admin/sales/shipments/view/10
禁用后,mod_cache
它mod_cache_disk
开始正常工作。有没有办法在不禁用这些的情况下修复此问题mods