伺服器之httpd

來源:互聯網
上載者:User

標籤:httpd

1:安裝啟動

yum install -y httpdsystemctl start httpdsystemctl stop firewalld

2:發佈頁面
預設發布目錄:/var/www/html/
預設發布檔案:index.html
[[email protected] html]# vim index.html
~~~~~~
<h1> 測試頁面內容</h1>
~~~~~~
systemctl restart httpd
測試:http://172.25.254.120

3:修改預設發布檔案
[[email protected] conf]# vim /etc/httpd/conf/httpd.conf

175 <IfModule dir_module>176     DirectoryIndex index.html    ##將index.html變成你想要更改的發布目錄177 </IfModule>

4:更改預設發布目錄

[[email protected] conf]# vim /etc/httpd/conf/httpd.confDocumentRoot "/zpy/html"   ##要更改的發布目錄<Directory "/zpy/html">    Require all granted   ##允許所有人訪問[[email protected] conf]semanage fcontext -a -t httpd_sys_content_t ‘/zpy(/.*)?‘  ##更改發布目錄的selinux安全上下文[[email protected] conf]restorecon -RvvF /zpy/           ##重新整理systemctl restart httpd.service

測試:http://172.25.254.120
5:設定使用者的黑名單和白名單

[[email protected] conf]# vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html">Require all granted   ##允許所有訪問Order  Allow  Deny  ##此處的順序和是否可以訪問有關Allow from http://172.25.254.120Deny from ALL</Directory>

systemctl restart httpd
測試:在172.25.254.20上開啟瀏覽器訪問http://172.25.254.120 了可以看到測試頁
但是其他ip地址開啟的不能訪問
6:對頁面加密
(1)製作密碼

[[email protected] Desktop]# cd /etc/httpd/conf[[email protected] conf]# lshttpd.conf  magic[[email protected] conf]# htpasswd -cm authfile admin  ##注,此處-cm表示建立authfile檔案,之前的檔案內容將被覆蓋掉,所以如果要建立兩個或以上使用者時用-cNew password: Re-type new password: Adding password for user admin[[email protected] conf]# cat authfile admin:$apr1$LQWb.7Yj$jSkQLKJwAn4JtRW9gnmHP

(2)添加密碼給測試頁

[[email protected] conf]# vim /etc/httpd/conf/httpd.conf<Directory "/zpy/html">#    Require all granted     AuthUserFile /etc/httpd/conf/authfile     ##添加加密檔案     AuthName "please into nameand passwd"     ##顯示標語     AuthType basic     Require user admin           ##允許admin使用者登陸#    Require valid-user           ##允許所有使用者登陸</Directory>

(3)測試
在測試時,當輸入http://172.25.254.120時候會彈出登陸頁面

7:在一台伺服器上開啟多個默任發布網頁
前提:配置好預設發布
mkdir /var/www/zpy/news.zpy.com -p
mkdir /var/www/zpy/music.zpy.com -p
echo "news.zpy.com‘page" /var/www/zpy/news.zpy.com/index.html
echo "music.zpy.com‘page"/var/www/zpy/music.zpy.com/index.html
vim /etc/httpd/conf.d/default.conf
~~~~~~

<Virtualhost _default_:80>    DocumentRoot "/var/www/html"    CustomLog "logs/default.log" combined</Virtualhost>

~~~~~~
vim /etc/httpd/conf.d/news.conf
~~~~~~~

<Virtualhost *:80>    ServerName news.zpy.com    DocumentRoot /var/www/zpy/news.zpy.com    CustomLog "logs/news.log" combined</Virtualhost><Directory "/var/www/zpy/news.zpy.com">    Require all granted</Directory>

~~~~~~~
vim /etc/httpd/conf.d/music.conf
~~~~~~

<Virtualhost *:80>    ServerName music.zpy.com    DocumentRoot /var/www/zpy/music.zpy.com    CustomLog "logs/music.log" combined</Virtualhost><Directory "/var/www/zpy/music.zpy.com">    Require all granted</Directory>

~~~~~~
systemctl restart httpd
測試:
在任意台伺服器上配置本地解析

[[email protected] Desktop]# cat /etc/hosts
172.25.254.120    www.zpy.com    music.zpy.com    news.zpy.com

訪問 www.zpy.com  出現預設發佈頁面
訪問 music.zpy.com 出現news.zpy.com‘page發佈頁面
訪問 news.zpy.com  出現news.zpy.com‘page發佈頁面


本文出自 “12462896” 部落格,請務必保留此出處http://12472896.blog.51cto.com/12462896/1955748

伺服器之httpd

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.