Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache 2.4 multiple sites with different alias and path

I have installed Ubuntu 16.04 with apache 2.4.18 in my local network.

I want to have two diffrent websites, identified by a /blah, there for i want to work with aliases, like:

192.168.2.134/wiki => /var/www/dokuwiki

192.168.2.134/sip => /var/www/rsip/public (Laravel)

For that i have configured /etc/apache2/sites-available/dokuwiki.conf with:

<VirtualHost *:80>
    DocumentRoot /var/www/
    ServerName 192.168.2.134:80/wiki
    Alias /wiki /var/www/dokuwiki
    <Directory /var/www/dokuwiki>
        Order deny,allow
        Allow from all
        Options FollowSymLinks
    </Directory>
</VirtualHost>

And /etc/apache2/sites-available/rsip.conf with:

<VirtualHost *:80>
    DocumentRoot /var/www/
    ServerName 192.168.2.134:80/sip
    Alias /sip /var/www/rsip/public
    <Directory /var/www/rsip/public/>
        AllowOverride All
        Require all granted
        Options FollowSymLinks
    </Directory>
</VirtualHost>

In /etc/apache2/apache2.conf there is:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options -Indexes
    Options FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

I have enabled the two sites and reloaded apache2.

Result of apachectl -S is:

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server 192.168.2.134 (/etc/apache2/sites-enabled/dokuwiki.conf:1)
         port 80 namevhost 192.168.2.134 (/etc/apache2/sites-enabled/dokuwiki.conf:1)
         port 80 namevhost 192.168.2.134 (/etc/apache2/sites-enabled/rsip.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

Result of apachectl -M is:

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php7_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)

The problem is, the link to 192.168.2.134/wiki works fine all the time, but the link to 192.168.2.134/sip brings up a 404 File not found and also maps to the wrong path, as i can see in /var/log/apache2/error.log:

[Wed Jul 18 22:00:16.601623 2018] [core:info] [pid 4686] [client 192.168.2.156:25896] AH00128: File does not exist: /var/www/sip/

If i try 192.168.2.134/rsip/public it works.

I think it has to do with the sequence of virtualhosts, like seen when executing apachectl -S, like shown above..

then if i do a2dissite dokuwiki.conf and reload apache2, the link to 192.168.2.134/sip works also fine. When i enable the 192.168.2.134/wiki again, the 192.168.2.134/sip again doesn't works.

Is it - in general - possible to do, what i am trying to do?!

btw: in /var/www/rsip/public/.htaccess is:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        #Options -MultiViews -Indexes
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteBase /sip

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

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ dashboard/$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
like image 800
Daniel Avatar asked Jan 27 '23 18:01

Daniel


1 Answers

ServerName directive should not have a /blah but only [scheme://]domain-name|ip-address[:port]. You should have something like this instead :

<VirtualHost *:80>
    DocumentRoot /var/www/
    ServerName 192.168.2.134:80
    Alias /wiki /var/www/dokuwiki
    Alias /sip /var/www/rsip/public
    <Directory /var/www/dokuwiki>
        Order deny,allow
        Allow from all
        Options FollowSymLinks
    </Directory>
    <Directory /var/www/rsip/public/>
        AllowOverride All
        Require all granted
        Options FollowSymLinks
    </Directory>
</VirtualHost>
like image 146
Andre Gelinas Avatar answered Jan 30 '23 06:01

Andre Gelinas