<Directory "/var/www/html">
Options None
AllowOverride None
AuthType Basic
AuthName "String"
AuthUserFile "/etc/httpd/conf/.httpdpasswd"
AuthGroupFile "/etc/httpd/conf/.grp"
<RequireAll>
Require ip 172.20
Require user ops1
</RequireAll>
</Directory>
基于用戶組進(jìn)行控制:
創(chuàng)新互聯(lián)專注于饒平企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),商城網(wǎng)站建設(shè)。饒平網(wǎng)站建設(shè)公司,為饒平等地區(qū)提供建站服務(wù)。全流程定制開發(fā),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)<Directory "/var/www/html">
Options None
AllowOverride None
AuthType Basic
AuthName "String"
AuthUserFile "/etc/httpd/conf/.httpdpasswd"
AuthGroupFile "/etc/httpd/conf/.grp"
<RequireAll>
Require ip 172.20
Require group ops
</RequireAll>
</Directory>
(2)提供賬號(hào)和密碼存儲(chǔ)(文本文件)
使用專用命令完成此類文件的創(chuàng)建及用戶管理
htpasswd [options] /PATH/TO/HTTPD_PASSWD_FILE username
-c:自動(dòng)創(chuàng)建此處指定的文件,因此,僅應(yīng)該在此文件不存在時(shí)使用;
-m:md5格式加密
-s: sha格式加密
-D:刪除指定用戶
-b:批模式添加用戶
[root@localhost conf]# htpasswd -bc /etc/httpd/conf/.httppasswd ops1 123456
Adding password for user ops1
[root@localhost conf]# vim /etc/httpd/conf/.grp
ops:ops1 ops2
(3)重啟測(cè)試:[root@localhost conf.d]# systemctl restart httpd
2.虛擬主機(jī)的配置
(1)基于IP地址的虛擬主機(jī)
[root@localhost /]# mkdir /data/html/{a,b} -pv
mkdir: created directory ‘/data/html’
mkdir: created directory ‘/data/html/a’
mkdir: created directory ‘/data/html/b’
[root@localhost /]# vim /data/html/a/index.html
<h2>hello a</h2>
[root@localhost /]# vim /data/html/b/index.html
<h2>hello b</h2>
[root@localhost conf.d]# vim vhost_ip.conf
<VirtualHost 172.20.10.4:80>
ServerName www.a.com
DocumentRoot "/data/html/a/"
<Directory "/data/html/a/">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 172.20.10.7:80>
ServerName www.b.com
DocumentRoot "/data/html/b/"
<Directory "/data/html/b/">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
(2)基于端口的虛擬主機(jī):
[root@localhost conf.d]# vim vhost_ip.conf
Listen 8080
<VirtualHost 172.20.10.4:80>
ServerName www.a.com
DocumentRoot "/data/html/a/"
<Directory "/data/html/a/">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 172.20.10.4:8080>
ServerName www.b.com
DocumentRoot "/data/html/b/"
<Directory "/data/html/b/">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
(3)基于FQDN的虛擬主機(jī):
[root@localhost conf.d]# vim vhost_ip.conf
<VirtualHost 172.20.10.4:80>
ServerName www.a.com
DocumentRoot "/data/html/a/"
<Directory "/data/html/a/">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 172.20.10.4:80>
ServerName www.b.com
DocumentRoot "/data/html/b/"
<Directory "/data/html/b/">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
注意:如果是httpd-2.2,則使用基于FQDN的虛擬主機(jī)時(shí),需要事先使用如下指令:NameVirtualHost IP:PORT
3.實(shí)現(xiàn)https[root@localhost conf.d]# yum install -y mod_ssl
(1)構(gòu)建私有CA:
生成私鑰;
~]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)
生成自簽證書;
~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3655
-new:生成新證書簽署請(qǐng)求;
-x509:生成自簽格式證書,專用于創(chuàng)建私有CA時(shí);
-key:生成請(qǐng)求時(shí)用到的私有文件路徑;
-out:生成的請(qǐng)求文件路徑;如果自簽操作將直接生成簽署過的證書;
-days:證書的有效時(shí)長(zhǎng),單位是day;
為CA提供所需的目錄及文件;
~]# mkdir -pv /etc/pki/CA/{certs,crl,newcerts}
~]# touch /etc/pki/CA/{serial,index.txt}
~]# echo 01 > /etc/pki/CA/serial
(2)要用到證書進(jìn)行安全通信的服務(wù)器,需要向CA請(qǐng)求簽署證書
用到證書的主機(jī)生成私鑰;
~]# mkdir /etc/httpd/ssl
~]# cd /etc/httpd/ssl
~]# (umask 077; openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)
生成證書簽署請(qǐng)求
~]# openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr -days 365
在CA主機(jī)上簽署證書;
~]# openssl ca -in /etc/httpd/ssl/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
[root@localhost /]# vim /etc/httpd/conf.d/ssl.conf
DocumentRoot "/data/html/b/"
ServerName www.b.com:443
SSLCertificateFile /etc/httpd/ssl/httpd.csr
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key
<Directory "/data/html/b/">
Options None
AllowOverride None
Require all granted
</Directory>
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)頁(yè)標(biāo)題:httpd實(shí)現(xiàn)http簡(jiǎn)單功能-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)網(wǎng)址:http://jinyejixie.com/article46/jsjhg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站、網(wǎng)站改版、企業(yè)網(wǎng)站制作、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容