阿里云apache-CentOS

阿里云centos7.6原生根目录

两项工作

  • 打开80端口(iptables/firewalld/ali云安全组)
  • 安装apache

Part ONE 打开80端口

一、用iptables打开80端口

1、安装iptables:

//(阿里云centos7 默认 是使用的firewall,所以要使用iptables需先安装)
yum install iptables-services 

2、把端口加入到iptables中(加入之前,可使用iptables -L -n查看端口情况)

vim /etc/sysconfig/iptables

添加:

                        ---vim iptables---

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

:wq

3、重启iptables:

systemctl restart iptables.service

(重启后,使用 iptables -L -n查看)

二、centos7.x用firewall打开80端口

  1. filrwall开启相关命令:
// filrwall是否开启:
# systemctl status firewalld

// 启动:
 #systemctl start firewalld

//关闭:
 # systemctl stop firewalld

//开机禁用  :

 #systemctl disable firewalld

//开机启用  :

 #systemctl enable firewalld

2.查看防火墙是否开启的状态,以及开放端口的情况

#systemctl status firewalld.service

//如果没有开启firewalld
#systemctl enable firewalld
#firewall-cmd --list-all 
  1. 通过以下命令开放http 80 端口
//添加80端口
# firewall-cmd --zone=public  --add-port=80/tcp --permanent

命令末尾的--permanent表示用久有效,不加这句的话重启后刚才开放的端口就又失效了

4 .然后重启防火墙

//重载
 # firewall-cmd --reload
  1. 再次查看端口的开放情况:
//
# firewall-cmd --list-all

ports:里出现了 80 端口

public
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: dhcpv6-client ssh
  ports: 80/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

三 、在阿里云控制台上, 添加安全组规则

  • path:
云服务器ECS  ->  安全组 -> 安全组规则 -> 入方向 ->  添加安全组规则 
  • 填写必须的选项
*端口范围:80/80
*授权对象:0.0.0.0/0

确定。OK~

Part Two Apache安装

一、Apache安装

1.确保服务器系统处于最新状态

yum -y update

2.重启服务器

reboot

3.首先检查80端口是否已经开启

netstat -an | grep 80

详见 Part One
如果显示以下内容说明已经开启80端口

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
tcp        0      0 172.16.134.203:56088    100.100.30.25:80        ESTABLISHED
unix  3      [ ]         STREAM     CONNECTED     11809    
unix  2      [ ]         DGRAM                    11800    

4.安装Apache,并且安装扩展模块

yum -y install httpd httpd-manual httpd-devel mod_ssl mod_perl mod_auth_mysql

5.设置CentOS开机自动启动Apache服务

 systemctl enable httpd.service

6.检查Apache是否已经安装了开机自动启动

systemctl list-unit-files | grep httpd

如果显示以下内容说明已经完成自动启动安装

httpd.service                                 enabled 

7.启动Apache服务

systemctl start httpd.service

8.判断是否安装成功Apache服务

curl http://127.0.0.1

命令行界面正常显示一堆html、css代码,没有乱码,一般是成功了

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <title>Apache HTTP Server Test Page powered by CentOS</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <!-- Bootstrap -->
    <link href="/noindex/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="noindex/css/open-sans.css" type="text/css" />

<style type="text/css"><!--      

body {
  font-family: "Open Sans", Helvetica, sans-serif;
  font-weight: 100;
  color: #ccc;
  background: rgba(10, 24, 55, 1);
  font-size: 16px;
}

h2, h3, h4 {
  font-weight: 200;
}

h2 {
  font-size: 28px;
}

.jumbotron {
  margin-bottom: 0;
  color: #333;
  background: rgb(212,212,221); /* Old browsers */
  background: radial-gradient(ellipse at center top, rgba(255,255,255,1) 0%,rgba(174,174,183,1) 100%); /* W3C */
}

.jumbotron h1 {
  font-size: 128px;
  font-weight: 700;
  color: white;
  text-shadow: 0px 2px 0px #abc,
               0px 4px 10px rgba(0,0,0,0.15),
               0px 5px 2px rgba(0,0,0,0.1),
               0px 6px 30px rgba(0,0,0,0.1);
}

.jumbotron p {
  font-size: 28px;
  font-weight: 100;
}

.main {
   background: white;
   color: #234;
   border-top: 1px solid rgba(0,0,0,0.12);
   padding-top: 30px;
   padding-bottom: 40px;
}

.footer {
   border-top: 1px solid rgba(255,255,255,0.2);
   padding-top: 30px;
}

    --></style>
</head>
<body>
  <div class="jumbotron text-center">
    <div class="container">
      <h1>Testing 123..</h1>
        <p class="lead">This page is used to test the proper operation of the <a href="http://apache.org">Apache HTTP server</a> after it has been installed. If you can read this page it means that this site is working properly. This server is powered by <a href="http://centos.org">CentOS</a>.</p>
        </div>
  </div>
  <div class="main">
    <div class="container">
       <div class="row">
            <div class="col-sm-6">
                <h2>Just visiting?</h2>
                    <p class="lead">The website you just visited is either experiencing problems or is undergoing routine maintenance.</p>
                    <p>If you would like to let the administrators of this website know that you've seen this page instead of the page you expected, you should send them e-mail. In general, mail sent to the name "webmaster" and directed to the website's domain should reach the appropriate person.</p>
                    <p>For example, if you experienced problems while visiting www.example.com, you should send e-mail to "webmaster@example.com".</p>
                </div>
                <div class="col-sm-6">
                    <h2>Are you the Administrator?</h2>
                    <p>You should add your website content to the directory <tt>/var/www/html/</tt>.</p>
                    <p>To prevent this page from ever being used, follow the instructions in the file <tt>/etc/httpd/conf.d/welcome.conf</tt>.</p>

                    <h2>Promoting Apache and CentOS</h2>
                    <p>You are free to use the images below on Apache and CentOS Linux powered HTTP servers.  Thanks for using Apache and CentOS!</p>
                    <p><a href="http://httpd.apache.org/"><img src="images/apache_pb.gif" alt="[ Powered by Apache ]"></a> <a href="http://www.centos.org/"><img src="images/poweredby.png" alt="[ Powered by CentOS Linux ]" height="31" width="88"></a></p>
                </div>
            </div>
        </div>
        </div>
    </div>
      <div class="footer">
      <div class="container">
        <div class="row">
          <div class="col-sm-6">          
            <h2>Important note:</h2>
            <p class="lead">The CentOS Project has nothing to do with this website or its content,
            it just provides the software that makes the website run.</p>
            
            <p>If you have issues with the content of this site, contact the owner of the domain, not the CentOS project. 
            Unless you intended to visit CentOS.org, the CentOS Project does not have anything to do with this website,
            the content or the lack of it.</p>
            <p>For example, if this website is www.example.com, you would find the owner of the example.com domain at the following WHOIS server:</p>
            <p><a href="http://www.internic.net/whois.html">http://www.internic.net/whois.html</a></p>
          </div>
          <div class="col-sm-6">
            <h2>The CentOS Project</h2>
            <p>The CentOS Linux distribution is a stable, predictable, manageable and reproduceable platform derived from 
               the sources of Red Hat Enterprise Linux (RHEL).<p>
            
            <p>Additionally to being a popular choice for web hosting, CentOS also provides a rich platform for open source communities to build upon. For more information
               please visit the <a href="http://www.centos.org/">CentOS website</a>.</p>
          </div>
        </div>
          </div>
    </div>
  </div>
</body></html>

或者

如果在浏览器中输入服务器IP地址(127.40.171.11)显示Testing 123..就说明安装成功

二、常见操作

  1. 启动、终止、重启
systemctl start httpd.service #启动

systemctl stop httpd.service #停止

systemctl restart httpd.service #重启
  1. 设置开机启动/关闭
systemctl enable httpd.service            #开机启动

systemctl disable httpd.service           #开机不启动

systemctl list-unit-files | grep httpd     # 检查Apache是否已经安装了开机自动启动
  1. 检查httpd状态
systemctl status httpd.service  #检查状态
  1. 显示Apache版本信息
 httpd -v
  1. 使用yum安装Apache,并且安装所有扩展模块
 yum -y install httpd*
  1. 查看加载模块
 httpd -M
  1. 检查配置文件是否正确
httpd -t
  1. 显示所有命令
 httpd -q
  1. 检查Apache安装路径
whereis httpd
  1. 检查并且显示Apache相关安装包
rpm -qa | grep httpd
  1. 显示Apache详细相关信息
 yum info httpd
  1. 查看Apache安装位置
 rpm -ql httpd
  1. 删除Apache
 rpm -e httpd-* --nodeps

rpm -e httpd-2.4.6-67.el7.c和entos.6.x86_64 --nodeps
  1. 删除Apache,并且删除相关文件
yum -y remove httpd

三、相关配置与环境

Apache主配置文件:/etc/httpd/conf/httpd.conf

Apache主配置目录,可以将不同类型的配置分门别类放入这个目录中:/etc/httpd/conf.d/

Apache网站根目录:/var/www/html/

Apache日志文件目录:/var/log/httpd

参考:
阿里云centos7.x 打开80端口
CentOS7.6中安装Apache及Apache常见操作和配置说明

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,911评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,014评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 142,129评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,283评论 1 264
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,159评论 4 357
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,161评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,565评论 3 382
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,251评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,531评论 1 292
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,619评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,383评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,255评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,624评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,916评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,199评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,553评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,756评论 2 335

推荐阅读更多精彩内容