Apache Http Server配置手册
一、 Apache服务器配置
Apache程序是目前拥有很高市场占有率的Web服务程序之一,其跨平台和安全性广泛被认可且拥有快速、可靠、简单的API扩展。 它的名字取自美国印第安人土著语,寓意拥有高超的作战策略和无穷的耐性,在红帽RHEL5、6、7系统中一直作为默认的Web服务程序而使用。在CentOs系统中apache服务器的软件包名称叫做httpd,所以我们直接使用下面的语句在云服务器中配置Apache服务器。
#yum -y install httpd
其他关于Apache的常用命令:
启动apache服务器 #systemctl start httpd
设置开机自动启动 #systemctl enable httpd
关闭apache服务器 #systemctl stop httpd
二、 配置安全组
在配置Apache服务器之后,通常情况下我们并不能直接使用公网访问云服务器,但是阿里云轻量应用服务器是默认配置好了防火墙规则,当我们的云服务器没有绑定安全组或者配置了防火墙规则时,我们可以登录云服务器的管理控制台进行操作。
阿里云服务器配置步骤:
阿里云轻量应用服务器的控制台,可以自行添加规则
腾讯云服务器配置步骤:
腾讯云服务器是没有默认绑定安全组的,所以需要我们新建安全组进行绑定,具体的操作步骤如图2-图5所示
首先,打开腾讯云服务器的控制台,点击左侧的安全组。
其次,新建安全组,可以选择自定义模板,之后添加常用端口。
再次,回到云主机,进行绑定刚才新建的安全组。
完成Apache服务器和安全组的配置之后,将云服务器的公网IP键入浏览器的地址栏,你将会看到如下页面,提示你Apache服务器配置成功,
三、 上传网页
在web服务器配置成功后,我们可以在/var/www/html/目录下添加网页,这样再次访问服务器就可以看到我们的网页。
添加可以使用Xshell输入命令新建一个HTML文件,并对内容进行修改,但是并不建议这样操作。我们可以下载软件Xftp,将本地已经编写好的HTML文件上传至云服务器的/var/www/html/目录中,如图7所示。
四、 更改端口
通过第二部分的实践,我们学习了安全组的配置,如果我们想更改云服务器的访问端口,首先要在安全组中,或者防火墙规则中添加自定义的规则,在规则里输入你想自定义的端口号即可。关于如何配置安全组或防火墙规则,请参考本文档第二部分的内容,关于端口号的详细信息将在下一部分详述。
在添加好新的进入规则后,我们需要修改Apache服务器的配置文档,具体的文件是/etc/httpd/conf目录下的httpd.conf。我们可以使用软件Xftp找到此文档,右键使用记事本打开,用Ctrl+F找到文本中的Listen80,将80改成你自定义的端口号后保存退出即可。这时你再次访问云服务器时,就需要在公网IP后面加上:和你的端口号,例如公网IP为0.0.0.0,端口号修改为8080,这是需要在地址栏输入0.0.0.0:8080。
五、 端口简介
端口(port)在这里指逻辑端口,是逻辑意义上用于区分服务的端口,如TCP/IP协议中的服务端口,比如用于浏览网页服务的80端口,用于FTP服务的21端口等。一个IP地址的端口通过16bit进行编号,最多可以有65536个端口,即2^16个端口。端口是通过端口号来标记的,端口号只有整数,范围是从0 到65535。
从0到1023号端口是well known port,是不允许用户自定义使用的;端口号从1025到49151,它们松散地绑定于一些服务,也是说有许多服务绑定于这些端口,这些端口同样用于许多其他目的。这些端口多数没有明确的定义服务对象,不同程序可根据实际需要自己定义;从49152到65535为动态端口号,是可用于任意软件与任何其他的软件通信的端口数。
在此列举一些常用端口,如果想了解具体的端口信息可以访问:
https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml
常用端口号:[1]
· 20: File TransferProtocol (FTP) Data Transfer
· 21: File TransferProtocol (FTP) Command Control
· 22: Secure Shell (SSH)Secure Login
· 23: Telnet remotelogin service, unencrypted text messages
· 25: Simple MailTransfer Protocol (SMTP) E-mail routing
· 53: Domain Name System (DNS)service
· 80: HypertextTransfer Protocol (HTTP) used in the World Wide Web
· 110: Post Office Protocol (POP3)
· 119: Network NewsTransfer Protocol (NNTP)
· 123: Network Time Protocol (NTP)
· 143: InternetMessage Access Protocol (IMAP) Management of digital mail
· 161: SimpleNetwork Management Protocol (SNMP)
· 194: Internet Relay Chat (IRC)
· 443: HTTP Secure (HTTPS)HTTP over TLS/SSL
以下两段是来自W3C对端口的描述,可以参考一下。
“The TCP/IP port numbers below 1024 are specialin that normal users are not allowed to run servers on them. This is a securityfeature, in that if you connect to a service on one of these ports you can befairly sure that you have the real thing, and not a fake which some hacker hasput up for you.The normal port number for W3 servers is port 80. This numberhas been assigned to WWW by the Internet Assigned Numbers Authority, IANA.Whenyou run a server as a test from a non-priviliged account, you will normallytest it on other ports, such as 2784, 5000, 8001 or 8080.”[2]
“A port is an endpoint of communication within a node. Withina node there are many ports, identified by decimal numbers 0 to 32767. Ports 0to 1023 are reserved for so called "well known port" numbers. (Seefile /etc/services on unix). Priviledge (SYSPRV under VMS) is required to use anumber below 1024.Port numbers of 1024 and above are free for userapplications, although it is not possible to use one already in use.Tocommunicate, one side (normally the server) must either establish a numberedport and the other side (normally a client) must make a connection to it.”[3]
[1] https://en.wikipedia.org/wiki/Port_(computer_networking)
[2] https://www.w3.org/Daemon/User/Installation/PrivilegedPorts.html
[3] https://www.w3.org/History/1992/ ... /User/Internet.html