【问题标题】:Apache Virtual Host not working on Ubuntu 14.04 LTSApache 虚拟主机无法在 Ubuntu 14.04 LTS 上运行
【发布时间】:2014-11-14 23:23:16
【问题描述】:

我一直在使用this tutorial 在我的 Ubuntu 电脑上设置一个 Apache 虚拟主机。我创建了一个no-ip domain,我将使用它作为我的虚拟主机的主机名。我已经按照教程的每个步骤进行操作,但它不起作用。这是虚拟主机文件,它被命名为crm2plus.ddns.net.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.example.com

        ServerAdmin webmaster@crm2plus.ddns.net
        ServerName  crm2plus.ddns.net
        ServerAlias crm2plus.ddns.net
        DocumentRoot /var/www/crm2plus.ddns.net/public_html

        # 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>
<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
<Directory /var/www>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

我还在本地主机文件中添加了 ip 和域名对,如下所示:

23.253.21.201   shhasan.ddns.net
127.0.1.1       Ubuntu-Dev
127.0.0.1       localhost
99.250.71.177   crm2plus.ddns.net

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

当我通过 chrome 导航到 crm2plus.ddns.net 时,我得到了 web page not available pageshhasan.ddns.net 工作正常。当我在终端中输入 ssh-keygen -H -F crm2plus.ddns.net 时,什么都没有显示,但是当我输入 ssh-keygen -H -F shhasan.ddns.net 时,显示的是:

# Host shhasan.ddns.net found: line 14 type RSA

后跟 RSA 密钥。

我还查看了 Apache 错误和访问日志。错误日志中有很多重复这样的代码行:

[Fri Nov 14 17:44:50.304782 2014] [mpm_prefork:notice] [pid 21927] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.5 configured -- resuming normal operations
[Fri Nov 14 17:44:50.304801 2014] [core:notice] [pid 21927] AH00094: Command line: '/usr/sbin/apache2'
[Fri Nov 14 17:44:54.979832 2014] [mpm_prefork:notice] [pid 21927] AH00169: caught SIGTERM, shutting down

我搜索了caught SIGTERM, shutting down,发现这是正常操作的一部分。我不知道我要去哪里错了。它以前适用于shhasan.ddns.net,但不适用于crm2plus.ddns.net

非常感谢所有帮助和建议。


更新:

developer@Ubuntu-Dev:/etc/apache2$ ls apache2.conf apache2.conf.dpkg-dist conf-enabled httpd.conf magic mods-enabled ports.conf~ sites-enabled apache2.conf~ conf-available envvars httpd.conf~ mods-available ports.conf sites-available

developer@Ubuntu-Dev:/etc/apache2/sites-available$ ls 000-default.conf 000-default.conf~ 000-default.conf.dpkg-dist crm2plus.ddns.net.conf crm2plus.ddns.net.conf~ default.save default-ssl.conf shhasan.ddns.net.conf

developer@Ubuntu-Dev:/etc/apache2/sites-enabled$ ls crm2plus.ddns.net.conf shhasan.ddns.net.conf

apache2.conf缩短版:

Include /etc/phpmyadmin/apache.conf
ServerName localhost

Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride All
#    Order deny,allow
#    Deny from all
</Directory>

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

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

#<Directory /srv/>
#   Options Indexes FollowSymLinks
#   AllowOverride None
#   Require all granted
#</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>


LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

【问题讨论】:

  • 您启用了该网站吗?
  • 是的,我已启用它。这是教程的一部分。
  • apache 正在运行吗?运行/etc/init.d/apache2 status 看它是否启动。
  • @PeteyT ` /etc/init.d/apache2 status` --> ` * apache2 is running`

标签: linux apache ubuntu virtualhost


【解决方案1】:

您可以尝试在虚拟主机定义文件中使用 Apache2.4 语法进行访问控制,因为您使用的是 Apache2.4,然后如果您还没有激活 mod_access_compat.so 它应该可以工作,或者如果您有,您可以停用它.

<Directory /var/www>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>

我必须承认我更喜欢在 VH 定义中添加虚拟主机的访问控制。然后,您只需看一下就知道实际发生了什么。所以你可以考虑这样做。

<VirtualHost *:80>
    ServerAdmin webmaster@crm2plus.ddns.net
    ServerName  crm2plus.ddns.net
    ServerAlias www.crm2plus.ddns.net
    DocumentRoot /var/www/crm2plus.ddns.net/public_html

    <Directory /var/www/crm2plus.ddns.net/public_html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

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

另外,在 httpd.conf 文件中弄乱这个参数时应该小心

<Directory />
    Options FollowSymLinks
    AllowOverride All
#    Order deny,allow
#    Deny from all
</Directory>

这控制了 Apache 对根文件夹的访问,当然您不会希望 Apache 或您的 Apache 上的黑客访问宇宙。

所以我建议你把这个设置回

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

当然是再次使用 Apache2.4 语法。


更新:上述 VH 定义的略微编辑版本适用于 crm2plus.ddns.net

<VirtualHost *:80>

    ServerName crm2plus.ddns.net
        ServerAlias crm2plus.ddns.net
    ServerRoot /var/www/crm2plus.ddns.net/
    DocumentRoot /var/www/crm2plus.ddns.net/public_html

    <Directory "/var/www/crm2plus.ddns.net/public_html">
        Options +Indexes +FollowSymLinks
        Order allow,deny
        Allow from all
        AllowOverride All
    </Directory>


    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    ErrorLog ${APACHE_LOG_DIR}/crm2plus.ddns.net_error.log
    CustomLog ${APACHE_LOG_DIR}/crm2plus.ddns.net_access.log combined


</VirtualHost>

【讨论】:

  • mod_access_compat 如何禁用它?
  • 你不必这样做,它只是为旧的 2.2 语法提供兼容性。这些有帮助吗?
  • 你做sudo a2dismod mod_access_compat
  • sudo a2dismod mod_access_compat --> ERROR: Module mod_access_compat does not exist!
  • 那就不用担心了。使用 2.4 语法应该可以解决您的问题
【解决方案2】:

检查您的/etc/nsswitch.conf 文件。在我的 Ubuntu 14.04LTS 上,我必须换行:

hosts:          files mdns4_minimal [NOTFOUND=return] dns

到:

hosts:          dns files mdns4_minimal [NOTFOUND=return]

为了使虚拟主机工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 2016-06-11
    • 2021-11-14
    • 2014-07-10
    • 2014-03-03
    相关资源
    最近更新 更多