如何解决Codeigniter 4 多站点 Apache VirtualHost
我正在使用 Codeigniter 4 在同一个树莓派上配置 3 个不同的应用程序,这些应用程序将被三个不同的调用调用,如下所示:
blue.ddns.net
red.ddns.net
black.ddns.net
这些是路径:
/var/www/html/blue/public/index.php
/var/www/html/red/public/index.php
/var/www/html/black/public/index.php
以前我插入了一个 /var/www/html/.htaccess 文件,该文件对三个不同的调用进行了排序。 不熟悉 Apache(这是我第一次安装和配置它)我没有创建(作为一个好习惯)任何虚拟主机文件。 现在在我创建的 /etc/apache2/sites-availables/ (Apache 2.4) 中:
blue.ddns.net.conf
red.ddns.net.conf
black.ddns.net.conf
这里是文件的内容:
#
# black.ddns.net
#
<VirtualHost *:80>
ServerAdmin web@master.org
ServerName black.ddns.net
DocumentRoot /var/www/html/black/public/
<Directory />
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/html/black/public/>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
###### Codeigniter Conf ######
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ black/public/index.php?/$1 [L,QSA]
<ifModule mod_security2.c>
SecRuleEngine off
</ifModule>
</Directory>
ErrorLog /var/log/apache2/black-error.log
CustomLog /var/log/apache2/black-access.log combined
</VirtualHost>
在文件夹 /var/www/html/black/public/ 中有一个 .htaccess:
# Disable directory browsing
Options All -Indexes
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Checks to see if the user is attempting to access a valid file,# such as an image or css document,if this isn't true it sends the
# request to the front controller,index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed,all 404's
# can be sent to index.php,and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end
通过这个配置我可以读取文件
/var/www/html/black/public/index.php
但是,当我调用放置在资产文件夹(js、css、图像...)中的文件时,我收到 404 错误:
/var/www/html/black/public/assets/
即使我调用现有文件,也总是会解释文件 black/public/index.php。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。