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/

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

发表评论

要发表评论,您必须先登录

  • 75 Responses to “Centos7安装Http-yum方式”
    • EdwardPhymn

      buy medication without an rx <a href=" https://genericwdp.com/# ">india pharmacy</a>
      generic pills without a doctor prescription

    • Fjjuprest

      low cost viagra <a href="http://viagraonlinejc.com/ ">what happens when women take viagra </a> what is viagra made of

    • Kndnboop

      is there a generic for viagra <a href="http://viagratx.com/ ">viagra and diabetes</a> what if a woman takes viagra

    • Nbmoprest

      buy cialis brand <a href="http://buycialisxz.com/ ">http://buycialisxz.com/ </a> cialis 60

    • AhbzAniny

      high risk cash advance reviews <a href="http://daymoneygo.com/ ">payday loans around the world</a> allied cash advance niles

    • JbbnAniny

      leberschaden durch cialis <a href="http://ljcialishe.com/ ">acquisto cialis roma</a> precio de cialis en el salvador

    • positive effects of marijuana on the brain

      Two of a trade never agree.

    • LabxAniny

      cialis atrial fibrillation <a href="https://jecialisbn.com/ ">order cialis online no prescription canada</a> cialis for women free trial

    • KbbfIdovE

      viagra and things like it <a href="http://kloviagrli.com/ ">online viagra reviews </a> viagra vancouver

    • FqbbAniny

      advance mont de piete loan office <a href="http://ascashapply.com/ ">csi payday loans vernon bc</a> payday loan store barrington rd

    • cialis canada nqzwkw

      canadian pharmacy.reviews <a href="http://edpharmacystore.com/">try these out</a> the canadian pharmacy
      <a href=http://edpharmacystore.com/>home</a>

    • Jbnvblafe

      payday loan powell portland <a href="http://samcash21.com/ ">cash advance locations in laurel md</a> riverelk payday loans

    • Fbsgprest

      cialis american express <a href="http://llecialisjaw.com/ ">buy cialis tadalafil </a> best prices for generic cialis

    • Nbnhprest

      over the counter sildenafil <a href="http://vigedon.com/ ">female viagra pill online</a> female viagra for sale online

    • Kvaxboop

      installment payday loans maryland <a href="http://rirocash.com/ ">payday loan rosenberg texas</a> poor credit cash loans

    • Aqcfbopinnots

      cialis soft <a href="http://cialisvja.com/ ">brand cialis canada</a> cialis australia online

    • AhkdAniny

      online canadian discount pharmacy <a href="http://storerxpharmcanada.com/ ">canadian drugstore online</a> online pharmacy canada

    • JbbvAniny

      canadian pharmacy king <a href="http://canadianpharmnorx.com/ ">pharmacies online</a> canada pharmacies/account

    • LbsxAniny

      canada pharmacy online no script <a href="https://ssviagriia.com/ ">viagra vs cialis/strong></a> prescription drugs online without

    • KuikIdovE

      buy viagra toronto <a href="http://viagerkr.com/ ">buy viagra witout precription</a> cialis vs viagra reviews

    • FqhhAniny

      costco online pharmacy <a href="http://happyrxpharmacy21.com/ ">canadian pharma companies</a> cialis super active

    • Jbnbblafe

      buying drugs canada <a href="http://online21rxon.com/ ">pharmacy tech</a> bestsellers

    • Fvfcprest

      п»їed meds online without doctor prescription <a href="http://hopeviagrin.com/ ">online pharmacies in usa</a> generic viagra sildenfil citrate australia

    • Kbcxboop

      general health <a href="http://xuypharmacyonline.com/">canadadrugs</a> cheap prescription drugs online

    • Nncsprest

      generic viagra testimonials <a href="http://lightvigra.com/ ">viagra without pprescription</a> au viagra