Apache2虚拟主机不起作用(Debian 8)

时间:2018-06-23 12:12:28

标签: debian apache2 virtualhost

在过去的几天里,我看了很多教程,但是我没有让Apache的虚拟主机正常工作。让我描述一下我到目前为止所做的事情:

首先,我进行一个新的virtualhost配置: /etc/apache2/sites-available/myconf.conf 内容:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName      myurl.de
        ServerAlias     www.myurl.de

        DocumentRoot /var/www/myurl

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

</VirtualHost>

然后我通过以下方式启用了配置:

a2ensite myconf.conf

并禁用默认配置

a2dissite 000-default.conf

并启用

a2enmod rewrite

使用重新启动Apache

service apache2 restart

我还编辑了 / etc / hosts

1.2.3.4 myurl.de

但是id无效。它始终显示 /var/www/html/index.html 下的默认Apache网站。 当我删除它时,它显示 404错误 因此,我认为虚拟主机不起作用。 我在 /var/www/myurl/index.html

下放置一个 index.html

输出:

ls /etc/apache2/sites-enabled/

myconf.conf

的输出
apache2 -S

[Sat Jun 23 14:02:59.265895 2018] [core:warn] [pid 9030] AH00111: Config variable ${APACHE_LOCK_DIR} is not defined
[Sat Jun 23 14:02:59.266095 2018] [core:warn] [pid 9030] AH00111: Config variable ${APACHE_PID_FILE} is not defined
[Sat Jun 23 14:02:59.266169 2018] [core:warn] [pid 9030] AH00111: Config variable ${APACHE_RUN_USER} is not defined
[Sat Jun 23 14:02:59.266231 2018] [core:warn] [pid 9030] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined
[Sat Jun 23 14:02:59.266296 2018] [core:warn] [pid 9030] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Sat Jun 23 14:02:59.269434 2018] [core:warn] [pid 9030:tid 140109537470336] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:
Invalid Mutex directory in argument file:${APACHE_LOCK_DIR}

因此apache.conf中有一个错误,但是我没有更改配置中的任何内容,因此我重新安装了apache2几次。

apache2.conf的第74行是:

# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
Mutex file:${APACHE_LOCK_DIR} default

当我将其注释掉时,出现带有环境变量的下一个错误。为什么此变量有错误?

[Sat Jun 23 14:09:07.795593 2018] [core:warn] [pid 9149:tid 140289705994112] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
AH00543: apache2: bad user name ${APACHE_RUN_USER}

那是

service apache2 status

● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─forking.conf
   Active: inactive (dead) since Sat 2018-06-23 19:11:38 CEST; 3s ago
  Process: 11660 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 11644 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)

Jun 23 19:11:38 quintox-online apache2[11644]: Starting web server: apache2[Sat Jun 23 19:11:38.748239...ace8
Jun 23 19:11:38 quintox-online apache2[11644]: (98)Address already in use: AH00072: make_sock: could n...]:80
Jun 23 19:11:38 quintox-online apache2[11644]: (98)Address already in use: AH00072: make_sock: could n...0:80
Jun 23 19:11:38 quintox-online apache2[11644]: no listening sockets available, shutting down
Jun 23 19:11:38 quintox-online apache2[11644]: AH00015: Unable to open logs
Jun 23 19:11:38 quintox-online apache2[11644]: Action 'start' failed.
Jun 23 19:11:38 quintox-online apache2[11644]: The Apache error log may have more information.
Jun 23 19:11:38 quintox-online apache2[11644]: .
Jun 23 19:11:38 quintox-online apache2[11660]: Stopping web server: apache2.
Jun 23 19:11:38 quintox-online systemd[1]: Started LSB: Apache2 web server.
Hint: Some lines were ellipsized, use -l to show in full.

但是error.log为空。

我对用户 root 所做的整个配置,可以吗?

有人可以帮我吗?

非常感谢!

1 个答案:

答案 0 :(得分:0)

解决了。 当您输入

service apache2 status

我知道了

Jun 23 19:11:38 quintox-online apache2[11644]: (98)Address already in use: AH00072: make_sock: could n...]:80
Jun 23 19:11:38 quintox-online apache2[11644]: (98)Address already in use: AH00072: make_sock: could n...0:80

这意味着什么,某些进程已经在端口80上监听了。所以您需要找出它是什么:

netstat -ltnp | grep :80

然后您将获得如下输出:

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      523/lighttpd
tcp6       0      0 :::80                   :::*                    LISTEN      523/lighttpd

您会看到进程ID-> 523(您的ID可以不同) 然后运行(使用您的ID)

sudo kill -9 523

之后,您可以开始使用Apache

service apache2 start

并输入

service apache2 status

您可以看到,它现在正在运行。 我的虚拟主机现在可以正常工作。

我在here

中找到了解决方案