Linux之web服務的搭建

來源:互聯網
上載者:User

標籤:linux web服務

今天我來給大家分享一下在Linux下搭建web伺服器

1、安裝包

yum install httpd

安裝完成後我們會在/etc目錄下看到有一個httpd的目錄

我們的預設檔案存放位置在/var/www/html

然後修改我們的注設定檔

vim /etc/httpd/conf/httpd.confServerName 自己的主機名稱:80

表示服務名稱為自己的主機名稱,監聽在80連接埠

然後就可以建檔案了

vim /var/www/html/index.htmlhello

這就是我們的首頁檔案了

然後我們開啟一下我的HTTP服務

service httpd start

然後我們就可以在另外一台虛擬機器上測試了

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/45/53/wKiom1PnU9rBjKcEAAD8fxMplho336.jpg" title="圖片1.png" alt="wKiom1PnU9rBjKcEAAD8fxMplho336.jpg" />


這就簡單的搭建好一台web伺服器了。

註:如果顯示無法串連,可能是你的防火牆給擋在牆外了,需要關閉防火牆才行。


2、建立基於檔案的存取控制

首先我們需要建立一個目錄

cd /var/www/htmlmkdir adminmkdir bbsvim bbs/index.htmlhello a vim /etc/httpd/conf/httpd.conf<Directory "/var/www/html/admin">       Options none       Allowoverride AuthConfig       AuthType Basic       AuthName "Admin Area."       AuthUserFile /etc/httpd/conf/.httpasswd       Require valid-user</Directory>

然後做使用者名稱和密碼存放檔案

htpasswd -c -m /etc/httpd/conf/.httpasswd tomtomtomhtpasswd  -m /etc/httpd/conf/.httpasswd jryjryjry

然後重讀一下設定檔

 service httpd reload

當我們再次訪問時就會彈出輸入使用者名稱和密碼了

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/45/54/wKioL1PnZa_xuggTAARlHU-NVTg503.jpg" title="圖片2.png" alt="wKioL1PnZa_xuggTAARlHU-NVTg503.jpg" />


3、基於組的存取控制配置

在2的基礎上,我們建立一個檔案

vim /etc/httpd/conf/.httpgrouptest:tom

添加test組,群組成員為tom,然後再編輯設定檔,把上個執行個體中的檔案內容修改如下

 vim /etc/httpd/conf/httpd.conf<Directory "/var/www/html/admin">      Options none      Allowoverride AuthConfig      AuthType Basic      AuthName "Admin Area."      AuthUserFile /etc/httpd/conf/.httpasswd      AuthGroupFile /etc/httpd/conf/.httpgroup      Require group test</Directory>

然後重讀設定檔

service httpd reload

然後我們分別登陸tom和jry查看

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/45/57/wKioL1Pnh-fSn2sqAARjf40nC5k912.jpg" title="圖片3.png" alt="wKioL1Pnh-fSn2sqAARjf40nC5k912.jpg" />


4、基於連接埠做虛擬機器主機

編輯主設定檔

vim /etc/httpd/conf/httpd.conf添加Listen 8080  開啟監聽8080連接埠#DocumentRoot "/var/www/html"  注釋掉中心主機配置,這樣虛擬機器主機配置才會生效<VirtualHost 172.16.249.29:80>           ServerName www.jsh.com           DocumentRoot "/web/hosta"</VirtualHost> <VirtualHost 172.16.249.29:8080>           ServerName www.jsh.com           DocumentRoot "/web/hostb"</VirtualHost>

設定檔語法檢查

 httpd -t

建立對應的目錄,並提供分頁檔

mkdir -pv /web/host{a,b}vim /web/hosta/index.htmlhello hostavim /web/hostb/index.htmlhello  hostb

然後重讀設定檔

service httpd restart

然後就可以測試了


650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/45/56/wKiom1PnhvSg-CmPAAH-QksBnrI059.jpg" style="float:none;" title="圖片4.png" alt="wKiom1PnhvSg-CmPAAH-QksBnrI059.jpg" />

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/45/57/wKioL1PniBajO-LDAAH4mooXvWM691.jpg" style="float:none;" title="圖片5.png" alt="wKioL1PniBajO-LDAAH4mooXvWM691.jpg" />

5、基於IP的虛擬機器主機

步驟跟4執行個體中的一樣,只用把第二個IP地址改為其他IP即可,並把8080連接埠改為80。



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.