阿里云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.查看防火墻是否開啟的狀態(tài),以及開放端口的情況

#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:里出現(xiàn)了 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: 

三 钥顽、在阿里云控制臺上, 添加安全組規(guī)則

  • path:
云服務器ECS  ->  安全組 -> 安全組規(guī)則 -> 入方向 ->  添加安全組規(guī)則 
  • 填寫必須的選項
*端口范圍:80/80
*授權對象:0.0.0.0/0

確定靠汁。OK~

Part Two Apache安裝

一蜂大、Apache安裝

1.確保服務器系統(tǒng)處于最新狀態(tài)

yum -y update

2.重啟服務器

reboot

3.首先檢查80端口是否已經(jīng)開啟

netstat -an | grep 80

詳見 Part One
如果顯示以下內容說明已經(jīng)開啟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是否已經(jīng)安裝了開機自動啟動

systemctl list-unit-files | grep httpd

如果顯示以下內容說明已經(jīng)完成自動啟動安裝

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 >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 >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 ><img src="images/apache_pb.gif" alt="[ Powered by Apache ]"></a> <a ><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 >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 >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是否已經(jīng)安裝了開機自動啟動
  1. 檢查httpd狀態(tài)
systemctl status httpd.service  #檢查狀態(tài)
  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

三五督、相關配置與環(huán)境

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

Apache主配置目錄,可以將不同類型的配置分門別類放入這個目錄中:/etc/httpd/conf.d/

Apache網(wǎng)站根目錄:/var/www/html/

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

參考:
阿里云centos7.x 打開80端口
CentOS7.6中安裝Apache及Apache常見操作和配置說明

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末瓶殃,一起剝皮案震驚了整個濱河市充包,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌遥椿,老刑警劉巖基矮,帶你破解...
    沈念sama閱讀 221,273評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異修壕,居然都是意外死亡愈捅,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,349評論 3 398
  • 文/潘曉璐 我一進店門慈鸠,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人灌具,你說我怎么就攤上這事青团。” “怎么了咖楣?”我有些...
    開封第一講書人閱讀 167,709評論 0 360
  • 文/不壞的土叔 我叫張陵督笆,是天一觀的道長。 經(jīng)常有香客問我诱贿,道長娃肿,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,520評論 1 296
  • 正文 為了忘掉前任珠十,我火速辦了婚禮料扰,結果婚禮上,老公的妹妹穿的比我還像新娘焙蹭。我一直安慰自己晒杈,他們只是感情好,可當我...
    茶點故事閱讀 68,515評論 6 397
  • 文/花漫 我一把揭開白布孔厉。 她就那樣靜靜地躺著拯钻,像睡著了一般。 火紅的嫁衣襯著肌膚如雪撰豺。 梳的紋絲不亂的頭發(fā)上粪般,一...
    開封第一講書人閱讀 52,158評論 1 308
  • 那天,我揣著相機與錄音污桦,去河邊找鬼亩歹。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的捆憎。 我是一名探鬼主播舅柜,決...
    沈念sama閱讀 40,755評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼躲惰!你這毒婦竟也來了致份?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,660評論 0 276
  • 序言:老撾萬榮一對情侶失蹤础拨,失蹤者是張志新(化名)和其女友劉穎氮块,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體诡宗,經(jīng)...
    沈念sama閱讀 46,203評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡滔蝉,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,287評論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了塔沃。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片蝠引。...
    茶點故事閱讀 40,427評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖蛀柴,靈堂內的尸體忽然破棺而出螃概,到底是詐尸還是另有隱情,我是刑警寧澤鸽疾,帶...
    沈念sama閱讀 36,122評論 5 349
  • 正文 年R本政府宣布吊洼,位于F島的核電站,受9級特大地震影響制肮,放射性物質發(fā)生泄漏冒窍。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,801評論 3 333
  • 文/蒙蒙 一豺鼻、第九天 我趴在偏房一處隱蔽的房頂上張望综液。 院中可真熱鬧,春花似錦拘领、人聲如沸意乓。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,272評論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽届良。三九已至,卻和暖如春圣猎,著一層夾襖步出監(jiān)牢的瞬間士葫,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,393評論 1 272
  • 我被黑心中介騙來泰國打工送悔, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留慢显,地道東北人爪模。 一個月前我還...
    沈念sama閱讀 48,808評論 3 376
  • 正文 我出身青樓,卻偏偏與公主長得像荚藻,于是被迫代替她去往敵國和親屋灌。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,440評論 2 359

推薦閱讀更多精彩內容