我们有一个网站(文件夹名称/srv/www/vhosts/wp-内部网托管在我们 LAN 中的服务器上。我们需要为其配备 Vhost,以便可以通过以下方式访问该网站:http://192.168.20.25/内联网“和/或”http://intranet.mycompany.de“
我按照文档中的说明操作,但不起作用。这是 VirtualHost 配置(/etc/apache2/vhost.d/wp-intranet.conf)
<VirtualHost 192.168.20.25>
ServerName intranet.mycompany.de
DocumentRoot /srv/www/vhosts/wp-intranet
ServerAdmin [email protected]
ErrorLog /var/log/apache2/intranet.mycompany.de_errorlog
CustomLog /var/log/apache2/intranet.mycompany.de_customlog common
<Directory "/srv/www/vhosts/wp-intranet">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
我也添加到NameVirtualHost *:80
了/etc/apache2/listen.conf
。
然后我在 Windows 客户端上创建了一个主机条目:
192.168.20.25 intranet.mycompany.de
但如果我从我的 Windows 计算机导航到intranet.mycompany.de
,那么该文件/srv/www/htdocs/index.html
就会打开。
我还重新启动了 apache 服务(service apache2 restart
)
我希望有人能给我指出正确的方向。文档没有帮助,我按照每个步骤操作,但仍然不起作用。
答案1
在里面<VirtualHost>
指示,语法为<VirtualHost addr[:port] [addr[:port]] ...>
。虽然支持 IP 地址的完全限定域名,但不建议这样做。由于 ApacheHost:
通过ServerName
(以及可选的ServerAlias
)将主机名与标头区分开来,因此您不需要它。尝试<VirtualHost *:80>
。
答案2
我终于解决了。官方文档缺少重要信息并且不是最新的。
我必须包含我的 vhost 配置文件/etc/apache2/vhost.d/wp-intranet.conf在/etc/apache2/httpd.conf
IncludeOptional /etc/apache2/vhosts.d/wp-intranet.conf
然后我注意到我无法重新启动服务 apache2。
apache2.service 的作业失败,因为控制进程退出并显示错误代码。有关详细信息,请参阅“systemctl status apache2.service”和“journalctl -xe”。
我执行systemctl status apache2.service
并得到:
● apache2.service - The Apache Webserver
Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2018-07-10 12:59:07 CEST; 10s ago
Process: 2017 ExecStop=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k graceful-stop (code=exited, status=1/FAILURE)
Process: 7622 ExecReload=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k graceful (code=exited, status=0/SUCCESS)
Process: 2008 ExecStart=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k start (code=exited, status=1/FAILURE)
Main PID: 2008 (code=exited, status=1/FAILURE)
Jul 10 12:59:07 intern start_apache2[2008]: AH00526: Syntax error on line 8 of /etc/apache2/vhosts.d/wp-i...onf:
Jul 10 12:59:07 intern start_apache2[2008]: Invalid command 'Order', perhaps misspelled or defined by a m...tion
Jul 10 12:59:07 intern systemd[1]: apache2.service: Main process exited, code=exited, status=1/FAILURE
Jul 10 12:59:07 intern start_apache2[2017]: AH00548: NameVirtualHost has no effect and will be removed in...f:41
Jul 10 12:59:07 intern start_apache2[2017]: AH00526: Syntax error on line 8 of /etc/apache2/vhosts.d/wp-i...onf:
Jul 10 12:59:07 intern start_apache2[2017]: Invalid command 'Order', perhaps misspelled or defined by a m...tion
Jul 10 12:59:07 intern systemd[1]: apache2.service: Control process exited, code=exited status=1
Jul 10 12:59:07 intern systemd[1]: Failed to start The Apache Webserver.
Jul 10 12:59:07 intern systemd[1]: apache2.service: Unit entered failed state.
Jul 10 12:59:07 intern systemd[1]: apache2.service: Failed with result 'exit-code'.
Hint: Some lines were ellipsized, use -l to show in full.
所以我发现官方文档中的虚拟主机配置有语法错误。我不得不将其更改为:
<VirtualHost *:80>
ServerName intranet.mycompany.de
DocumentRoot /srv/www/vhosts/wp-intranet
ServerAdmin [email protected]
ErrorLog /var/log/apache2/intranet.mycompany.de_errorlog
CustomLog /var/log/apache2/intranet.mycompany.de_customlog common
<Directory "/srv/www/vhosts/wp-intranet">
#Order allow,deny
AllowOverride All
#Allow from all
Require all granted
</Directory>
</VirtualHost>
现在我可以重新启动 apache2 了,如果我导航到http://intranet.mycompany.de/
wordpress 网站就会打开!