【问题标题】:Apache Virtualhost on different port redirecting to DefaultRoot不同端口上的 Apache Virtualhost 重定向到 DefaultRoot
【发布时间】:2018-08-02 14:57:32
【问题描述】:

我正在尝试使用 apache 2.4 设置为监听不同端口的虚拟主机

在端口 80 上:纯 HTML 页面。 在端口 81 上:一个 Angular6 应用程序。

在我的 0_web.conf 上

<VirtualHost *:80>
    ServerName web
    DocumentRoot /var/www/html/web
        DirectoryIndex index.html

    <Directory /var/www/html/web>
       AllowOverride all
    </Directory>
</VirtualHost>

在front.conf中

Listen 81
<VirtualHost *:81>
    ServerName munitdp
    <Directory /var/www/dist/>
        RewriteEngine on

        # Don't rewrite files or directories
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^ - [L]

        # Rewrite everything else to index.html
        # to allow html5 state links
        RewriteRule ^ index.html [L]
    </Directory>
</VirtualHost>

我正在使用亚马逊 ec2 服务器。现在我没有任何域,所以我访问像http://ec2-18-xxx-xxx-xxx.us-west-2.compute.amazonaws.com/这样的网址

apachectl -S 的输出

VirtualHost configuration:
*:80                   web (/etc/httpd/conf.d/0_web.conf:1)
*:81                   munitdp (/etc/httpd/conf.d/front.conf:2)
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex default: dir="/run/httpd/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex cache-socache: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex watchdog-callback: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
Mutex lua-ivm-shm: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48

当我输入 http://ec2-18-xxx-xxx-xxx.us-west-2.compute.amazonaws.com/ 时,我进入了 html 页面,但访问 http://ec2-18-xxx-xxx-xxx.us-west-2.compute.amazonaws.com:81 后,我进入了“/ 的索引”,列出了 web/。

有什么想法吗?我在这里碰壁了。

【问题讨论】:

  • 当没有虚拟主机与特定 url 匹配时,apache 使用第一个虚拟主机。您的端口 81 的虚拟主机具有服务器名称 munitdp,因此 url 与该名称不匹配,因此正在使用第一个虚拟主机。您可以尝试从第二个虚拟主机中删除 servername 指令吗?
  • 完成。结果还是一样。

标签: apache


【解决方案1】:

我没有看到在第二个 vHost 中定义的 DocumentRoot。可能会添加

DocumentRoot /var/www/dist/

到你的front.conf

【讨论】:

  • 就是这样。我觉得很愚蠢,因为没有注意到它。谢谢!
猜你喜欢
  • 2017-02-17
  • 2021-06-26
  • 1970-01-01
  • 1970-01-01
  • 2015-04-24
  • 2012-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多