Centos7安装Http-yum方式

1、Httpd安装步骤
1.1下载阿里的base和epel源:

[root@httpd-2 ~]# cd /etc/yum.repos.d/
[root@httpd-2 yum.repos.d]# rm -rf *.repo
[root@httpd-2 yum.repos.d]# wget https://mirrors.aliyun.com/repo/Centos-7.repo
[root@httpd-2 yum.repos.d]# https://mirrors.aliyun.com/repo/epel-7.repo
修改base源:
[root@httpd-2 yum.repos.d]# vi Centos-7.repo
#删除阿里内部使用的下边两个网址
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/

1.2安装httpd

[root@httpd-2 ~]# yum install httpd –y

使用yum源安装时,httpd的版本一般不会是最新的,最新的版本只能去Apache官网下载源码包安装。

1.3启动httpd

[root@httpd-2 ~]# systemctl start httpd
[root@httpd-2 ~]# systemctl enable httpd    //设置开机自启

1.4查看httpd状态
查看httpd进程:

[root@httpd-2 ~]# ps -ef | grep httpd
root       1976      1  0 16:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     1977   1976  0 16:53 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     1978   1976  0 16:53 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     1979   1976  0 16:53 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     1980   1976  0 16:53 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     1981   1976  0 16:53 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
root       2002   1753  0 16:54 pts/0    00:00:00 grep --color=auto httpd
yum方式安装会自动创建一个apache用户,以这用户的方式启动服务。

查看httpd端口:

[root@httpd-2 ~]# netstat -lntup | grep httpd
tcp6       0      0 :::80         :::*           LISTEN      1976/httpd  

至此,安装httpd已经完成。接下来介绍httpd的各种网页及配置文件。

2、站点根目录的配置
2.1 站点根目录和首页文件
站点根目录:是用来存放网页文件的目录,里面有许多文件,其中就有首页文件。如果是静态文件,首页文件名称通常是index.html,index.htm,如果是动态网页,首页文件名称可能是index.jsp或者index.php。

查找首页文件:
[root@httpd-2 ~]# grep "DirectoryIndex" /etc/httpd/conf/httpd.conf
# DirectoryIndex: sets the file that Apache will serve if a directory
DirectoryIndex index.html
[root@httpd-2 ~]# grep "DocumentRoot" /etc/httpd/conf/httpd.conf             
# DocumentRoot: The directory out of which you will serve your
DocumentRoot "/var/www/html"

[root@httpd-1 ~]# grep "DirectoryIndex" /app/httpd/conf/httpd.conf
DirectoryIndex index.html
[root@httpd-1 ~]# grep "DocumentRoot" /app/httpd/conf/httpd.conf               
DocumentRoot "/app/httpd-2.4.37/htdocs"
DocumentRoot定义站点根目录,DirectoryIndex定义首页文件,因此首页文件全路径是:/var/www/html/index.html。

这里说明一下源码包安装的httpd和yum源安装的httpd的重要文件位置的区别:
主配置目录:
源码包位于手动指定目录下的conf/httpd.conf;yum的位于/etc/httd/conf/httpd.conf。

二进制命令存放目录:
源码包位于手动指定目录下的bin/目录;yum的位于/usr/sbin/目录。

日志存放目录:
源码包位于手动指定目录下的logs/目录;yum的位于/var/log/httpd/目录。

网页文件存放目录(站点根目录):
源码包位于手动指定目录下的htdocs/目录;yum的位于/var/www/html/目录。

2.2 站点优化—禁止显示根目录
在首页文件不存在的情况下,浏览器访问网站可能会显示网站的目录结构,被黑客看到,会顺藤摸瓜,找到网站的漏洞进行入侵。所以,在首页文件不存在的情况下,一定要禁止显示网站的目录结果:

Centos7安装Http-yum方式

解决方法如下:

[root@httpd-2 ~]# cd /etc/httpd/conf/
[root@httpd-2 conf]# cp httpd.conf httpd.conf.bak
[root@httpd-2 conf]# vi httpd.conf
<Directory "/var/www/html">
    Options Indexes FollowSymLinks  //将这个Indexes删掉
[root@httpd-2 conf]# apachectl graceful
//源码包方式安装的也类似修改

修改完再次访问网站,就会报403错误,而不会显示站点的目录结构了。

此文章固定链接: http://www.rakbuluo.com/p60/

原文链接:,转发请注明来源!

发表评论

  • 28 Responses to “Centos7安装Http-yum方式”
    • Jvcxblafe

      online viagra <a href="http://fmedrx.com/#">viagra overnight mastercard canada canadian</a> where to buy viagra in edmonton generic soft viagra <a href="http://edabcrx.com/#">can i buy viagra without a prescription</a> no prescription viagra viagra canada customs <a href="http://abcrxmed.com/#">viagra online south africa</a> soft viagra viagra patent ending <a href="http://cialedrx.com/#">buy viagra in quebec</a> viagra product using viagra <a href="http://hitrxmenvia.com/#">viagra meaning</a> guaranteed viagra alternative

      回复
    • Klioboop

      generic viagra discover <a href="http://bestviagrx.com/#">viagracheap</a> which pharmacy can i buy viagra in london viagra over night <a href="http://viarxhd.com/#">viagra\\</a> generic viagra prices buy generic viagra 50mg <a href="http://viagetpill.com/#">viagra on line nz</a> order viagra with paypal shoppers drug mart viagra <a href="http://pillexrx.com/#">viagra online australia paypal</a> viagra sale viagra what dosage? <a href="http://usggrxmed.com/#">preview on viagra gold</a> viagra. no prescription

      回复
    • Fgnhprest

      buy viagra online australia <a href="http://ltdviagragogo.com/#">price viagra</a> order generic viagra viagra usa <a href="http://hdgenericviagraxk.com/#">what is better viagra or cialis</a> buy viagra with paypal uk where can i find the best and cheapest overnight viagra? <a href="http://buygenericviarga.com/#">viagra cialis samples</a> 50mg viagra viagra greate britain <a href="http://buyhdpillvia.com/#">buy cheap viagra on line</a> what ingredients inside viagra australian viagra <a href="http://genericviagrix.com/#">best prices for viagra</a> revatio vs viagra

      回复
    • Dvscprest

      thesis writer <a href="https://dissertationhelpvfh.com/#">help me with my essay about jesus christ</a> write good essay

      回复
    • FqfAniny

      essay writing about teachers <a href="https://essaywritingservicesjy.com/#">writing a good thesis statement for an essay</a> conclusion on research paper

      回复
    • FtghAniny

      awesome college essays <a href="https://thesiswritinghelpsjj.com/#">essays 1 timothy</a> geometry homework solver

      回复
    • FsfAniny

      theses dissertations <a href="https://essayhelpbgs.com/#">writing essay for college</a> writing a case study analysis paper

      回复
    • Kwgdboop

      college paper writing services <a href="https://researchpaperssfk.com/#">personal argument essay</a> writing an autobiography essay

      回复
    • Fgsprest

      criteria for essay writing <a href="https://writemypaperbuyhrd.com/#">help me write my bio</a> purdue owl essay writing

      回复
    • FnrhAniny

      buy viagraonline <a href="https://genqpviag.com/#">viagra without ed</a> viagra for sale in south africa

      回复
    • FnsbAniny

      library research paper <a href="https://customessaywriterbyz.com/#">do my algebra homework fast</a> creative phrases for essay writing

      回复
    • Jgscblafe

      essay writing in english <a href="https://thesisbyd.com/#">creating a thesis statement for an essay</a> essays about women

      回复
    • Kbrgboop

      where can i buy sildenafil over the counter <a href="https://miraclevigra.com/#">viagra online australia</a> us online pharmacy generic viagra

      回复
    • Fdbvprest

      viagra in usa online <a href="https://hopeviagrin.com/#">canadian pharmacy sildenafil 100mg</a> buy cheap generic viagra uk

      回复
    • FbsbAniny

      pseudo viagra <a href="https://genericrxxx.com/#">obtaining viagra prescription</a> viagra vs levitra forum

      回复
    • FnrdAniny

      purchasing viagra online for cheap <a href="https://llviabest.com/#">generic viagra 100mg sildenafil</a> i want to buy viagra from australia

      回复
    • FbsgAniny

      limbaugh arrested for viagra <a href="https://buybuyviamen.com/#">viagra pas cher en ligne</a> natural drug for viagra

      回复
    • Jsweblafe

      cheap viagra online free shipping australia <a href="https://mygoviagar.com/#">viagra shop</a> how much is viagra in australia

      回复
    • Devkprest

      price of viagra <a href="https://paradiseviagira.com/#">viagra without rx</a> where to buy no prescription viagra with discover card

      回复
    • Kmrfboop

      is viagra safe long term <a href="https://purevigra.com/#">https://purevigra.com</a> can you take viagra when your drunk

      回复
    • Frbhprest

      viagra with dapoxetine <a href="https://paradiseviagira.com/#">paradiseviagira.com</a> viagra melbourne victoria

      回复
    • FhsbAniny

      ankit fadia selling viagra <a href="https://buybuyviamen.com/#">https://buybuyviamen.com</a> viagra illegal japan

      回复
    • FevbAniny

      buy genaric viagra <a href="https://wowviaprice.com/#">https://wowviaprice.com</a> cheepviagra

      回复
    • Jivhblafe

      kan en tjej ta viagra <a href="https://purevigra.com/#">viagra jest bez recepty</a> lyrics to viagra 2 chainz

      回复
    • KmrfAniny

      ordering viagra online http://usggrxmed.com/ <a href="http://usggrxmed.com/#">online viagra</a> buy viagra online without

      回复
    • JildcAniny

      cheap viagra generic http://fmedrx.com/ <a href="http://fmedrx.com/#">buy generic viagra online india</a> buy viagra online no prescription

      回复
    • buy cialis 5mg online

      does cialis work Ovekly https://biracialism.com/ - Cialis DICIVE Wirkung Viagra Lange Oppone <a href=https://biracialism.com/#>Cialis</a> immazy Cephalexin Paralysis Dog

      回复
    • cialis online without

      Viagra Kaufen Munchen Ovekly https://biracialism.com/ - Cialis DICIVE Como Partir Proscar Propecia Oppone <a href=https://biracialism.com/#>cheap cialis online</a> immazy Levitra Selbstversuch

      回复