Apache2 虚拟主机不工作 (Debian 8)

Apache2 Virtual Hosts did not work (Debian 8)

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

首先我做了一个新的虚拟主机配置: /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下面放了一个index.html。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 进行的整个配置,可以吗?

有人可以帮我吗?

非常感谢!

解决了。 当你输入

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

您可以看到,现在是 运行ning。 我的虚拟主机现在可以使用了。

我在 here

中找到了解决方案