我有一个托管多个网站的WHM。每个网站都托管在/home/<hostname>/public_html
。我的一个网站是使用Laravel 5.4。显然这个网站运行不正常。
所以我将所有文件直接推送到public_html并按照此帖Laravel 5 - Remove public from URL将资产文件路由到public/
。但资产文件不会从网站路由到public/
文件夹。
这是.htaccess
文件:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} !(\.svg|\woff|\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|img|fonts)/(.*)$ public/$1/$2 [L,NC]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
它适用于我的测试服务器。我不知道为什么它在我的生产服务器上不起作用。当我去网站。 apacge error_log文件显示以下错误:
File does not exist: /usr/local/apache/htdocs/home
多次。
.htaccess
由apache服务器解析,因为我试图弄乱文件,网站显示500错误。
我不知道这是因为虚拟主机配置错误还是什么错误。这是虚拟主机配置:
<VirtualHost 123.164.132.142:80>
ServerName marca.com
ServerAlias mail.marca.com www.marca.com
DocumentRoot /home/marca/public_html
ServerAdmin webmaster@marca.com
UseCanonicalName Off
CustomLog /usr/local/apache/domlogs/marca combined
CustomLog /usr/local/apache/domlogs/marca.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User marca # Needed for Cpanel::ApacheConf
UserDir enabled
<IfModule mod_suphp.c>
suPHP_UserGroup marca marca
</IfModule>
<IfModule !mod_disable_suexec.c>
<IfModule !mod_ruid2.c>
SuexecUserGroup marca marca
</IfModule>
</IfModule>
<IfModule mod_ruid2.c>
RMode config
RUidGid marca marca
</IfModule>
<IfModule itk.c>
# For more information on MPM ITK, please read:
# http://mpm-itk.sesse.net/
AssignUserID marca marca
</IfModule>
ScriptAlias /cgi-bin/ /home/marca/public_html/cgi-bin/
# To customize this VirtualHost use an include file at the following location
# Include "/usr/local/apache/conf/userdata/std/2_2/marca/marca.com/*.conf"
</VirtualHost>
服务器正在使用apache 2.2。
编辑: 当我直接访问公用文件夹时。索引路线显示正确。但是当我去其他路线如/ login时,该网站显示404错误。并且.env可供全世界访问。
我应该补充一点,我的服务器托管了多个php版本的多个网站。这个Laravel网站使用PHP 5.6.31及其自己的配置文件。
/usr/local/apache/conf/php56.conf
<IfModule mod_suphp.c>
<Directory ~ "/home/marcabymortise/public_html">
Options +FollowSymLinks
AllowOverride All
AddType application/x-httpd-php56 .php
suPHP_AddHandler application/x-httpd-php56
</Directory>
</IfModule>
我还没有自定义虚拟主机文件。
这是/usr/local/apache/conf/httpd.conf
文件。
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Direct modifications to the Apache configuration file may be lost upon subsequent regeneration of the #
# configuration file. To have modifications retained, all modifications must be checked into the #
# configuration system by running: #
# /usr/local/cpanel/bin/apache_conf_distiller --update
.....
Include "/usr/local/apache/conf/php.conf"
....
<Directory "/">
Options ExecCGI IncludesNOEXEC Indexes SymLinksIfOwnerMatch
AllowOverride All
</Directory>
<Directory "/usr/local/apache/htdocs">
Options Includes Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Files ~ "^error_log$">
Order allow,deny
Deny from all
Satisfy All
</Files>
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog "logs/access_log" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
</IfModule>
<Directory "/usr/local/apache/cgi-bin">
AllowOverride All
Options None
Order allow,deny
Allow from all
</Directory>
<IfModule mod_log_config.c>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
CustomLog logs/access_log common
</IfModule>
....
答案 0 :(得分:0)
将服务器升级到Apache 2.4后。现在工作正常。