我正在尝试设置一个小型 VPS。当它为我配置时,我得到了一个 ip 地址,它显示了一个 apache2 页面。我更喜欢使用 nginx 进行设置。我向主机商询问是否可以切换到 nginx,并得到了:
Apache is included with the template used to create the server.
All software installation, removal, updating and configuration is up to the end user. We provide pre-made server templates to you of the most commonly used software packages to help you get started.
基于https://www.cyberciti.biz/faq/ubuntu-linux-start-restart-stop-apache-web-server/,我正在尝试使用以下命令关闭 Apache 服务器:
deploy@server:~$ sudo systemctl stop apache2.service
deploy@server:~$ sudo systemctl status apache2.service
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: inactive (dead) since Thu 2017-01-12 21:24:23 EST; 4 days ago
Docs: man:systemd-sysv-generator(8)
Process: 28696 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCES
Process: 28681 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCC
Jan 17 11:09:17 server systemd[1]: Stopped LSB: Apache2 web server.
Warning: Journal has been rotated since unit was started. Log output is incomplete
但默认页面在 URL 上仍然可见。我做错了什么?
编辑:
deploy@server:~$ journalctl -xe
Hint: You are currently not seeing messages from other users and the system.
Users in the 'systemd-journal' group can see all messages. Pass -q to
turn off this notice.
No journal files were opened due to insufficient permissions.
deploy@server:~$ sudo service apache2 stop
[sudo] password for deploy:
deploy@server:~$
网页仍然处于活动状态。请注意,deploy 是我创建的非 root 帐户。
编辑2:
deploy@server:~$ ps aux | egrep apache2
deploy 17196 0.0 0.1 11228 888 pts/0 S+ 12:22 0:00 grep -E --color=auto apache2
编辑3:我发现以下内容:
The binary is called apache2. Due to the use of environment variables, in the default configuration, apache2 needs to be started/stopped with /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not work with the default configuration.
编辑4:我切换到根:
root@server:/var/www/html# /etc/init.d/apache2 stop
[ ok ] Stopping apache2 (via systemctl): apache2.service.
root@server:/var/www/html#
没有变化。我还编辑了 index.html 文件中的文本,并且可以正确显示。
编辑5:
root@server:/var/www/html# sudo systemctl stop apache2.service
root@server:/var/www/html# lynx http://localhost
我仍然可以在 Lynx 浏览器中看到该网页
编辑6:
root@server:/var/www/html# sudo lsof -i tcp:80 | egrep LISTEN
nginx 28487 root 6u IPv4 603899449 0t0 TCP *:http (LISTEN)
nginx 28487 root 7u IPv6 603899450 0t0 TCP *:http (LISTEN)
nginx 28488 www-data 6u IPv4 603899449 0t0 TCP *:http (LISTEN)
nginx 28488 www-data 7u IPv6 603899450 0t0 TCP *:http (LISTEN)
编辑7:
root@server:/var/www/html# sudo update-rc.d -f apache2 remove
root@server:/var/www/html# sudo systemctl status apache2.service
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: inactive (dead)
Docs: man:systemd-sysv-generator(8)
Jan 17 12:59:58 server apache2[17860]: Action 'start' failed.
Jan 17 12:59:58 server apache2[17860]: The Apache error log may have more inform
Jan 17 12:59:58 server apache2[17860]: *
Jan 17 12:59:58 server apache2[17876]: * Stopping Apache httpd web server apach
Jan 17 12:59:58 server apache2[17876]: *
Jan 17 12:59:58 server systemd[1]: Started LSB: Apache2 web server.
Jan 17 13:01:04 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 14:16:05 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 14:16:54 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 14:20:45 server systemd[1]: Stopped LSB: Apache2 web server.
编辑8:
Jan 17 13:01:04 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 14:16:05 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 14:16:54 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 14:20:45 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 16:38:44 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 16:41:50 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 16:50:48 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 16:51:20 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 16:51:33 server systemd[1]: Stopped LSB: Apache2 web server.
Jan 17 16:51:45 server systemd[1]: Stopped LSB: Apache2 web server.
root@server:/var/www/html# sudo update-rc.d -f apache2 remove
root@server:/var/www/html#
答案1
感谢您的输出。您最初用于停止服务的命令运行正常。
您看到的页面是另一台机器上运行的 Web 服务的一个实例。
您必须使用 DNS 服务来指向您为 Web 服务器分配的机器。
您还可以通过在本地计算机(启动 apache2 服务器的同一台计算机)上运行 Web 浏览器并在 Web 浏览器中加载此地址来验证这一点:
http://localhost
解决方案是为您的 Apache 服务器设置虚拟主机,然后配置您的名称服务器以指向您配置的虚拟主机的 IP 地址。
http://localhost
当您停止服务(您的原始命令)时,在本地计算机上运行浏览器进行加载将失败。当您在本地计算机上启动 apache 服务时,它将加载默认页面(替换stop
为start
原始命令中的)。
根据您的问题更新和评论,您正在运行两个 Web 服务器...Apache2
和Nginx
。在同一个 IP 地址/端口上运行它们将会产生冲突,因为缺少确定将数据发送到何处的方法。
根据您的偏好Nginx
,您可以使用以下方式禁用 Apache:
$ sudo update-rc.d -f apache2 remove