当前位置 主页 > 服务器问题 > Linux/apache问题 >

    CentOS 7中 Apache Web 服务器安装配置教程(2)

    栏目:Linux/apache问题 时间:2019-03-12 13:48

    # sample configuration for iptables service# you can edit this manually oruse system-config-firewall# please donot ask us to add additional ports/services to thisdefault configuration*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -p tcp -m state --state NEW -m tcp --dport 22-j ACCEPT-A INPUT -p tcp -m state --state NEW -m tcp --dport 80-j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT

    我在文件的倒数第三行上添加了一个新行,它允许在端口 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 ServerLoaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)Active: active (running) since Thu2018-02-0813:18:54 EST;5s agoDocs: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 -DFOREGROUNDFeb0813:18:54 testvm1 systemd[1]:StartingTheApache HTTP Server...Feb0813:18:54 testvm1 systemd[1]:StartedTheApache HTTP Server.

    您的服务器上的命令可能不同。在使用 SystemV 启动脚本的 Linux 系统上,命令如下:

    [root@testvm1 ~]# service httpd startStarting httpd:[FriFeb0908:18:072018]     [ OK ][root@testvm1 ~]# service httpd statushttpd (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```