我在使用 Apache 時遇到問題。我剛剛安裝了 Centos,想要建立一個自己的網路伺服器。我正在遵循“centos 7.2 的完美伺服器「並在我的機器上遇到了這個錯誤
[root@server01 /]# sudo systemctl start httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
[root@server01 /]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2016-11-02 14:04:03 PDT; 14s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 30113 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
Process: 30065 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
Main PID: 30065 (code=exited, status=1/FAILURE)
Nov 02 14:04:01 server01.tcforwarding.com systemd[1]: Starting The Apache HTTP Server...
Nov 02 14:04:02 server01.tcforwarding.com httpd[30065]: [Wed Nov 02 14:04:02.346089 2016] [alias:warn] [pid 30065] AH00671: The Scri...Alias.
Nov 02 14:04:02 server01.tcforwarding.com httpd[30065]: AH00548: NameVirtualHost has no effect and will be removed in the next relea...nf:356
Nov 02 14:04:02 server01.tcforwarding.com httpd: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
Nov 02 14:04:02 server01.tcforwarding.com systemd: httpd.service: main process exited, code=exited, status=1/FAILURE
Nov 02 14:04:02 server01.tcforwarding.com kill: kill: cannot find process ""
Nov 02 14:04:03 server01.tcforwarding.com systemd httpd.service: control process exited, code=exited status=1
Nov 02 14:04:03 server01.tcforwarding.com systemd: Failed to start The Apache HTTP Server.
Nov 02 14:04:03 server01.tcforwarding.com systemd: Unit httpd.service entered failed state.
Nov 02 14:04:03 server01.tcforwarding.com systemd: httpd.service failed.
有人可以幫我解決這個問題嗎?
運行sudo netstat -nap | grep :80
回報
[root@server01 /]# sudo netstat -nap | grep :80
tcp 0 0 192.168.0.22:56616 104.16.13.8:80 TIME_WAIT -
tcp 0 0 192.168.0.22:43882 151.101.193.69:80 ESTABLISHED 6833/firefox
tcp 0 0 192.168.0.22:37556 151.101.129.69:80 ESTABLISHED 6833/firefox
tcp 0 0 192.168.0.22:37722 151.101.65.69:80 ESTABLISHED 6833/firefox
tcp 0 0 192.168.0.22:47506 151.101.1.69:80 ESTABLISHED 6833/firefox
tcp 0 0 192.168.0.22:55722 54.225.161.140:80 ESTABLISHED 6833/firefox
tcp 0 0 192.168.0.22:40710 107.14.33.34:80 ESTABLISHED 6833/firefox
tcp 0 0 192.168.0.22:43884 151.101.193.69:80 ESTABLISHED 6833/firefox
tcp 0 0 192.168.0.22:39374 50.16.185.14:80 ESTABLISHED 6833/firefox
tcp 0 0 192.168.0.22:57408 104.16.12.8:80 ESTABLISHED 6833/firefox
tcp6 0 0 2605:e000:9290:cf:57260 2607:f8b0:4007:80c::443 ESTABLISHED 6833/firefox
tcp6 0 0 2605:e000:9290:cf:42280 2607:f8b0:4007:801:::80 ESTABLISHED 6833/firefox
tcp6 0 0 2605:e000:9290:cf:35994 2607:f8b0:4007:80c::443 ESTABLISHED 6833/firefox
tcp6 0 0 2605:e000:9290:cf:42210 2607:f8b0:4007:80b:::80 ESTABLISHED 6833/firefox
現在關閉 Firefox 後執行相同的命令
[root@server01 /]# sudo netstat -nap | grep :80
tcp 0 0 192.168.0.22:39514 151.101.129.69:80 TIME_WAIT -
tcp 0 0 192.168.0.22:39516 151.101.129.69:80 TIME_WAIT -
tcp 0 0 192.168.0.22:57042 54.243.224.230:80 TIME_WAIT -
tcp 0 0 192.168.0.22:59396 104.16.12.8:80 TIME_WAIT -
tcp 0 0 192.168.0.22:39734 151.101.65.69:80 TIME_WAIT -
tcp 0 0 192.168.0.22:58596 104.16.13.8:80 TIME_WAIT -
tcp 0 0 192.168.0.22:39510 151.101.129.69:80 TIME_WAIT -
tcp 0 0 192.168.0.22:37124 96.6.122.178:80 TIME_WAIT -
tcp 0 0 192.168.0.22:39696 151.101.65.69:80 TIME_WAIT -
tcp 0 0 192.168.0.22:57710 54.225.161.140:80 TIME_WAIT -
tcp 0 0 192.168.0.22:47790 64.95.32.61:80 TIME_WAIT -
tcp6 0 0 2605:e000:9290:cf:33722 2607:f8b0:4007:80b::443 TIME_WAIT -
tcp6 0 0 2605:e000:9290:cf:53536 2607:f8b0:4007:801::443 TIME_WAIT -
tcp6 0 0 2605:e000:9290:cf:58196 2607:f8b0:4007:806:::80 TIME_WAIT -
tcp6 0 0 2605:e000:9290:cf:51876 2607:f8b0:4007:800::443 TIME_WAIT -
現在再次運行此命令systemctl status httpd.service
我仍然遇到相同的錯誤
[root@server01 /]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2016-11-02 20:34:28 PDT; 9s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 17357 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
Process: 17343 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
Main PID: 17343 (code=exited, status=1/FAILURE)
Nov 02 20:34:27 server01.tcforwarding.com systemd[1]: Starting The Apache HTTP Server...
Nov 02 20:34:28 server01.tcforwarding.com httpd[17343]: [Wed Nov 02 20:34:28.202720 2016] [alias:warn] [pid 17343] AH00671: The Scr...Alias.
Nov 02 20:34:28 server01.tcforwarding.com httpd[17343]: AH00548: NameVirtualHost has no effect and will be removed in the next rele...nf:356
Nov 02 20:34:28 server01.tcforwarding.com httpd[17343]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
Nov 02 20:34:28 server01.tcforwarding.com systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Nov 02 20:34:28 server01.tcforwarding.com kill[17357]: kill: cannot find process ""
Nov 02 20:34:28 server01.tcforwarding.com systemd[1]: httpd.service: control process exited, code=exited status=1
Nov 02 20:34:28 server01.tcforwarding.com systemd[1]: Failed to start The Apache HTTP Server.
Nov 02 20:34:28 server01.tcforwarding.com systemd[1]: Unit httpd.service entered failed state.
Nov 02 20:34:28 server01.tcforwarding.com systemd[1]: httpd.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
問題仍然阻止我啟動
運行命令nmap 192.168.0.1
返回
Starting Nmap 6.40 ( http://nmap.org ) at 2016-11-06 15:52 PST
Nmap scan report for server01.tcforwarding.com (192.168.0.1)
Host is up (0.000016s latency).
Not shown: 992 closed ports
PORT STATE SERVICE
21/tcp open ftp
25/tcp open smtp
53/tcp open domain
110/tcp open pop3
143/tcp open imap
993/tcp open imaps
995/tcp open pop3s
3306/tcp open mysql
Nmap done: 1 IP address (1 host up) scanned in 0.15 seconds
為什麼連接埠 80 或連接埠 443 根本不顯示?
答案1
您已經在連接埠 80 上執行某些內容。
sudo netstat -nap | grep ':80 .*LISTEN'
答案2
我會說使用 nmap 來查看正在運行哪些服務以及在哪個連接埠上運行。 nmap 結果看起來像這樣...
$ nmap 192.168.50.25
...
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
80/tcp open http <~ make sure service is http
443/tcp open https
如果除 http 之外的其他內容正在使用連接埠 80,您可以變更 apache 配置並將其指向不同的連接埠,或將使用連接埠 80 的服務變更為其他連接埠。這是安裝 nmap 的指南
答案3
首先你應該使用指令:
netstat -natup |grep 80
你應該讓我們知道哪個服務正在運行,如果連接埠80被其他服務使用,你必須殺死它。
如果這樣還不能解決問題,可以檢查httpd.conf的權限,檢查是否有以下指令:
listen [::]:80
因為我們可以知道您的系統日誌中的錯誤
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
有時這個問題是由 ipv6 引起的,所以你應該在你的conf中加入該指令
listen [::]:80 ipv6only=off default_server;
然後重啟httpd服務就可以了