当前位置 主页 > 服务器问题 > Linux/apache问题 >
我在文件的倒数第三行上添加了一个新行,它允许在端口 80 上输入流量。现在我重新加载 iptables 配置文件。
[root@testvm1 ~]#cd/etc/sysconfig/; iptables-restore iptables
创建 index.html 文件
index.html 文件是你使用域名访问网站而不是访问特定网页时的默认文件。在 /var/www/html 中,创建一个名字为 index.html 的文件,在其中添加字符串 Hello World 。你不需要添加任何的 HTML 标志去完成这项工作。web 服务器的唯一任务是提供文本数据流,服务器不知道数据是什么,也不知道如何呈现它。它只是将数据流传输给请求主机。
保存文件后,将所有权设置为 apache.apache 。
[root@testvm1 html]#chown apache.apache index.html
启动 Apache
Apache 很容易启动。 当前版本的 Fedora 使用 systemd 。 运行以下命令启动它,然后检查服务器的状态:(LCTT 译注: systemctl 是一个 systemd 工具)
[root@testvm1 ~]#systemctl start httpd [root@testvm1 ~]#systemctl status httpd ● httpd.service -TheApache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Thu2018-02-0813:18:54 EST;5s ago Docs:man:httpd.service(8) Main PID:27107(httpd) Status:"Processing requests..." Tasks:213(limit:4915) CGroup:/system.slice/httpd.service ├─27107/usr/sbin/httpd -DFOREGROUND ├─27108/usr/sbin/httpd -DFOREGROUND ├─27109/usr/sbin/httpd -DFOREGROUND ├─27110/usr/sbin/httpd -DFOREGROUND └─27111/usr/sbin/httpd -DFOREGROUND Feb0813:18:54 testvm1 systemd[1]:StartingTheApache HTTP Server... Feb0813:18:54 testvm1 systemd[1]:StartedTheApache HTTP Server.
您的服务器上的命令可能不同。在使用 SystemV 启动脚本的 Linux 系统上,命令如下:
[root@testvm1 ~]# service httpd start Starting httpd:[FriFeb0908:18:072018] [ OK ] [root@testvm1 ~]# service httpd status httpd (pid 14649)is running...
如果您的主机上有像 Firefox 或 Chrome 这样的浏览器,您可以在浏览器的 URL 行上使用 URL localhost 来显示您的 web 页面,尽管看起来很简单。您还可以使用像 Lynx 这样的文本模式 web 浏览器来查看 web 页面。首先,安装 Lynx (如果它还没有被安装)。
[root@testvm1 ~]# dnf -y install lynx
然后使用下面的命令来显示网页。
[root@testvm1 ~]# lynx localhost
结果在我的终端中是这样的。我已经删除了页面上的很多空白。
HelloWorld <snip> Commands:Use arrow keys to move,'?'for help,'q' to quit,'<-' to go back. Arrow keys:UpandDown to move.Right to follow a link;Left to go back. H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list```
接下来,编辑您的 index.html 文件并添加一些 HTML 标记,使其看起来像这样:
<h1>Hello World</h1>
现在刷新浏览器。对于 Lynx,使用组合键 Ctrl + R 。 结果看起来有点不同。如果你的终端支持彩色的话文本是彩色显示的,Lynx 会显示标题,现在它处于居中状态。 在 GUI 浏览器中,文本将以大字体显示。
HelloWorld <snip> Commands:Use arrow keys to move,'?'for help,'q' to quit,'<-' to go back. Arrow keys:UpandDown to move.Right to follow a link;Left to go back. H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list