我按照示例设置了虚拟主机文件/etc/httpd/conf.d/vhost.com.conf
,并多次检查我的文件和地址
<VirtualHost *:80>
ServerName www.vhost.com
ServerAlias vhost.com
DocumentRoot /var/www/html/vhost.com/public_html/
ErrorLog /var/www/html/vhost.com/logs/error.log
CustomLog /var/www/html/vhost.com/logs/access.log combined
</VirtualHost>
但是我的 Apache 没有启动并显示以下错误:
[seconduser@VPS- ~]$ sudo systemctl status httpd.service -l
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2016-07-03 11:44:58 IRDT; 54s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 7214 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
Process: 7212 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
Main PID: 7212 (code=exited, status=1/FAILURE)
Jul 03 11:44:58 VPS- systemd[1]: Starting The Apache HTTP Server...
Jul 03 11:44:58 VPS- httpd[7212]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::250:56ff:fea3:6805. Set the 'ServerName' directive globally to suppress this message
Jul 03 11:44:58 VPS- systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jul 03 11:44:58 VPS- kill[7214]: kill: cannot find process ""
Jul 03 11:44:58 VPS- systemd[1]: httpd.service: control process exited, code=exited status=1
Jul 03 11:44:58 VPS- systemd[1]: Failed to start The Apache HTTP Server.
Jul 03 11:44:58 VPS- systemd[1]: Unit httpd.service entered failed state.
Jul 03 11:44:58 VPS- systemd[1]: httpd.service failed.
一旦我删除vhost.com.conf
一切,就会恢复正常,服务器会在另一个配置中再次运行,我将此代码添加到我的vhost.com.conf
:
<VirtualHost *:80>
ServerName www.vhost.com
ServerAlias vhost.com
DocumentRoot /var/www/vhost.com/public_html/
ErrorLog /var/www/vhost.com/logs/error.log
CustomLog /var/www/vhost.com/logs/access.log combined
</VirtualHost>
并发送此命令sudo chmod -R 755 /var/www
,sudo chown -R apache:apache /var/www/html/www.vhost.com
我不知道它们做什么,我只是在互联网上看到它们。
编辑- 我检查了我的错误日志/var/log/httpd/error_log
并收到此错误:(13)Permission denied: AH00091: httpd: could not open error log file /var/www/vhost.com/logs/error.log. AH00015: Unable to open logs
我该怎么办?
我这样做是因为我需要分离我的子域名。
答案1
您可能没有在 conf/httpd.conf 中启用 NameVirtualHost *:80 行
如果您正在使用端口 443,您可能还想为端口 443 添加一行。
以下命令是你的朋友:
apachectl configtest
httpd -S
ls -ltr /var/log/httpd
last 命令将显示按修改时间排序的日志目录;最近的在最后。当您不知道应该在哪个文件中找到信息时很有用。
答案2
这
Jul 03 11:44:58 VPS- httpd[7212]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::250:56ff:fea3:6805. Set the 'ServerName' directive globally to suppress this message
表示您没有在 中设置 ServerName /etc/httd/http.conf
。取消注释行 Servername,并将其设置为ServerName localhost
或服务器的 fqdn。
答案3
您应用了非常没有安全感 sudo chmod -R 755 /var/www
权限到您想要的日志目录,但仍然收到以下权限被拒绝错误:
(13)Permission denied: AH00091: httpd: could not open error log file /var/www/vhost.com/logs/error.log. AH00015: Unable to open logs
这很可能是因为 SELinux 拒绝访问造成的。Red Hat 7 手册提供了相当不错的分步指南,可帮助您确定 SELinux 是否确实是原因,以及如何解决 SELinux AVC 拒绝问题:https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/chap-Security-Enhanced_Linux-Troubleshooting.html
简而言之,您可能需要执行以下操作:
sudo chcon -t httpd_log_t /var/www/vhost.com/logs /var/www/vhost.com/logs/*
将日志目录标记为日志的 apache 目标。