AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1033632
Accepted
Uri
Uri
Asked: 2020-09-13 03:04:41 +0800 CST2020-09-13 03:04:41 +0800 CST 2020-09-13 03:04:41 +0800 CST

Apache 虚拟主机未按预期工作 - 我的网站被重定向到默认虚拟主机

  • 772

我正在使用 Ubuntu 18.04.1 LTS 配置新服务器(droplet)。我安装了 apache 并配置了虚拟主机。服务器名称是www.speedysoftware.com,这是 的值/etc/hostname。问题是,我试图将http://www.speedysoftware.com/重定向到特定的虚拟主机,但它被重定向到默认的虚拟主机。另一方面,http ://www.speedysoft.com/和http://www.speedy-software.com/被重定向到正确的虚拟主机,应该与http://www.speedysoftware 相同。 com/

文件/etc/apache2/sites-available/000-default.conf:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerAdmin [email protected]
    DocumentRoot /var/www/general

    <Directory /var/www/general>
        Options +FollowSymLinks
        Options -Indexes
        AllowOverride All
        Require all granted
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

文件/etc/apache2/sites-available/speedysoftware.conf:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName www.speedysoftware.com
    ServerAlias speedysoftware.com *.speedysoftware.com
    ServerAlias speedy-software.com *.speedy-software.com
    ServerAlias speedysoft.com *.speedysoft.com
    # ... (more ServerAliases)

    ServerAdmin [email protected]
    DocumentRoot /var/www/speedysoftware

    <Directory /var/www/speedysoftware>
        Options +FollowSymLinks
        Options -Indexes
        AllowOverride All
        Require all granted
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

可以看到http://www.speedy-soft.com/被重定向到默认的虚拟主机,这是正确的。配置有什么问题?

进行更改后,我重新加载了设置sudo systemctl restart apache2。

关于重定向,在这种情况下我不想重定向。我希望它们被视为独立的网站,尽管它们指向同一个虚拟主机。在其他情况下,我会重定向,例如我将http://www.speedypedia.org/重定向到http://www.speedypedia.info/,然后重定向http://ww.speedysoftware.com/(或任何其他子域,包括http://speedysoftware.com/)到http://www.speedysoftware.com/。

更新- 我检查了http://ww.speedysoftware.com/、http://www.speedysoftware.com/和http://speedysoftware.com/都指向正确的虚拟主机。只有http://www.speedysoftware.com/不会导致正确的虚拟主机。

virtualhost apache-2.4 ubuntu-18.04
  • 1 1 个回答
  • 1447 Views

1 个回答

  • Voted
  1. Best Answer
    Uri
    2020-09-13T03:04:41+08:002020-09-13T03:04:41+08:00

    我写信给 DigitalOcean 支持(顺便说一句,他们有很大的支持),他们写信给我:

    服务器是 Apache,因此您可以访问支持 -S 标志的 apachectl 命令以获取转储的已解析设置,其中包括建立它们的虚拟主机和配置。

    我apachectl -S从命令行运行并发现了问题:

    *:80                   is a NameVirtualHost
             default server www.speedysoftware.com (/etc/apache2/sites-enabled/000-default.conf:1)
             port 80 namevhost www.speedysoftware.com (/etc/apache2/sites-enabled/000-default.conf:1)
             ...
    

    由于我没有在 中定义ServerName,/etc/apache2/sites-available/000-default.conf因此采用了液滴名称,这就是问题所在。所以我添加ServerName www.speedy-soft.com到这个文件中:

    <VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName www.speedy-soft.com
    
        ServerAdmin [email protected]
        DocumentRoot /var/www/general
    
        <Directory /var/www/general>
            Options +FollowSymLinks
            Options -Indexes
            AllowOverride All
            Require all granted
        </Directory>
    
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
    </VirtualHost>
    
    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
    

    并重新启动 Apache。我又跑apachectl -S了:

    *:80                   is a NameVirtualHost
             default server www.speedy-soft.com (/etc/apache2/sites-enabled/000-default.conf:1)
             port 80 namevhost www.speedy-soft.com (/etc/apache2/sites-enabled/000-default.conf:1)
             ...
    

    现在一切正常。

    您可以在此页面上查看更多详细信息: https ://stackoverflow.com/questions/5474477/how-to-debug-an-apache-virtual-host-configuration

    • 0

相关问题

  • 阿帕奇虚拟主机

  • Apache:对多个虚拟主机使用相同的目录指令

  • Apache 中的动态虚拟主机

  • VirtualHost / NameVirtualHost 背后的逻辑是什么

  • 如何设置 Jetty 6 和 Jboss 4.0.5 虚拟主机?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve