laravel - Apache 2.4 具有不同别名和路径的多个站点

标签 laravel apache ubuntu alias virtualhost

我在本地网络中安装了 Ubuntu 16.04 和 apache 2.4.18。

我想要两个不同的网站,由 /blah 标识,在那里我想使用别名,例如:
192.168.2.134/wiki => /var/www/dokuwiki192.168.2.134/sip => /var/www/rsip/public (拉拉维尔)

为此我配置了/etc/apache2/sites-available/dokuwiki.conf和:

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

/etc/apache2/sites-available/rsip.conf和:
<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>

/etc/apache2/apache2.conf有:
<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>

我启用了这两个站点并重新加载了 apache2。
apachectl -S 的结果是:
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
apachectl -M 的结果是:
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)

问题是,192.168.2.134/wiki 的链接一直运行良好,但链接到 192.168.2.134/sip调出 404 File not found并且还映射到错误的路径,正如我在 /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/

如果我尝试 192.168.2.134/rsip/public有用。

我认为这与虚拟主机的顺序有关,就像在执行 apachectl -S 时看到的那样,如上图..

那么如果我这样做 a2dissite dokuwiki.conf并重新加载 apache2,链接到 192.168.2.134/sip工作也很好。当我启用 192.168.2.134/wiki再次,192.168.2.134/sip再次不起作用。

它 - 一般来说 - 有可能做,我想要做什么?!

顺便说一句:在 /var/www/rsip/public/.htaccess是:
<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>

最佳答案

ServerName 指令不应该有/blah,而应该只有 [scheme://]domain-name|ip-address[:port]。你应该有这样的东西:

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

关于laravel - Apache 2.4 具有不同别名和路径的多个站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51410460/

相关文章:

mysql - 起诉 Laravel 查询生成器时,每月计算客户数量不起作用

wordpress - 我安装了新的 SSL,现在只有一半的站点是安全的?

python - wxPython版本问题

linux - 如何强制所有请求都来 self 的网站以避免使用 Apache 进行欺骗

php - Eloquent & Carbon 时差

php - Laravel 在多数据库环境中使用错误的数据库

php - 如何使用 github action 部署 Laravel 应用程序

java - 从自定义 Web 服务器迁移到 apache Web 服务器

php - $_POST 在 php5.6 中为空

Ubuntu + Mono + ASP.NET,这可能吗?