2021年3月30日星期二

Codeigniter 4 multisite Apache VirtualHost

I am configuring on the same raspberry 3 different applications with Codeigniter 4 that will be invoked by three different calls like this:

blue.ddns.net  red.ddns.net  black.ddns.net  

These are the paths:

/var/www/html/blue/public/index.php  /var/www/html/red/public/index.php  /var/www/html/black/public/index.php  

Previously I had inserted a /var/www/html/.htaccess file that sorted the three different calls. Not being familiar with Apache (it is really the first time I install and configure it) I had not created (as a good practice) any virtual host file. Now instead in /etc/apache2/sites-availables/ (Apache 2.4) I created:

blue.ddns.net.conf  red.ddns.net.conf  black.ddns.net.conf  

Here is the content of the files:

#  # 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>  

In the folder /var/www/html/black/public/ there is an .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  

With this configuration I can read the file

/var/www/html/black/public/index.php  

However I get 404 error when I call the files placed in the assets folder (js, css, images...):

/var/www/html/black/public/assets/  

Even if I call an existing file, the file black/public/index.php is always interpreted.

https://stackoverflow.com/questions/66880702/codeigniter-4-multisite-apache-virtualhost March 31, 2021 at 10:07AM

没有评论:

发表评论