[root@xxx-xxx-xxx src]# yum install httpd 依存性を解決しました ============================================================================================= Package アーキテクチャー バージョン リポジトリー 容量 ============================================================================================= インストール中: httpd x86_64 2.4.6-89.el7.centos.1 updates 2.7 M 依存性関連でのインストールをします: apr x86_64 1.4.8-3.el7_4.1 base 103 k apr-util x86_64 1.5.2-6.el7 base 92 k httpd-tools x86_64 2.4.6-89.el7.centos.1 updates 91 k mailcap noarch 2.1.41-2.el7 base 31 k トランザクションの要約 ============================================================================================= インストール 1 パッケージ (+4 個の依存関係のパッケージ)
[root@xxx-xxx-xxx src]# rpm -qa |grep http httpd-tools-2.4.6-89.el7.centos.1.x86_64 httpd-2.4.6-89.el7.centos.1.x86_64
[root@xxx-xxx-xxx httpd]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:httpd(8) man:apachectl(8) [root@xxx-xxx-xxx conf]# systemctl start httpd [root@xxx-xxx-xxx conf]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since 金 2019-08-09 17:50:37 JST; 42s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 25686 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service tq25686 /usr/sbin/httpd -DFOREGROUND tq25687 /usr/sbin/httpd -DFOREGROUND tq25688 /usr/sbin/httpd -DFOREGROUND tq25689 /usr/sbin/httpd -DFOREGROUND tq25690 /usr/sbin/httpd -DFOREGROUND mq25691 /usr/sbin/httpd -DFOREGROUND 8月 09 17:50:37 xxx-xxx-xxx systemd[1]: Starting The Apache HTTP Server... 8月 09 17:50:37 xxx-xxx-xxx httpd[25686]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set th...is message 8月 09 17:50:37 xxx-xxx-xxx systemd[1]: Started The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full. [root@xxx-xxx-xxx conf]# systemctl stop httpd
參考
↓
修改Apache的配置文件/etc/httpd/conf/httpd.conf,對須要認證的資源所在的目錄進行配置。
cd /etc/httpd/conf/
cp -ip httpd.conf httpd.conf.bak190809
vi httpd.conf
註釋這2行配置:
# Options Indexes FollowSymLinks
# AllowOverride None
在註釋掉的AllowOverride None這行配置後追加如下配置:
# add begin
Options Indexes FollowSymLinks
AllowOverride authconfig
Order allow,deny
Allow from all
# add end
在限制訪問目錄/var/www/html下建立文件.htaccess。
cd /var/www/html
vi .htaccess
AuthName "Auth!!!!!!"
AuthType basic
AuthUserFile /var/www/html/members.txt
require valid-user
說明:.htaccess文件中經常使用的配置選項有如下幾個:
1) AuthName:定義提示信息,用戶訪問時提示信息會出如今認證的對話框中
2) AuthType:定義認證類型,在HTTP1.0中,只有一種認證類型:basic。在HTTP1.1中有幾種認證類型,如:MD5
3) AuthUserFile:定義包含用戶名和密碼的文本文件,每行一對
4) AuthGroupFile:定義包含用戶組和組成員的文本文件。組成員之間用空格分開,如:group1:user1 user2
5) require命令:定義哪些用戶或組才能被受權訪問。如:
require user user1 user2 (只有用戶user1和user2能夠訪問)
requires groups group1 (只有group1中的成員能夠訪問)
require valid-user (在AuthUserFile指定的文件中的全部用戶均可以訪問)
利用Apache附帶的程序htpasswd,生成包含用戶名和密碼的文本文件:/var/www/html/members.txt
htpasswd -bc /var/www/html/members.txt xxxx xxxx1234 #第一次添加用戶時member.txt文件不存在,須要用-c選項建立文件
htpasswd -b /var/www/html/members.txt xxxx xxxx1234
cat /var/www/html/members.txt
xxxx:$cpr1$J2M/x2/p$Nb9wDpNWzKxmHEgAvAKPt0
確認關閉httpd的自啓動!
systemctl is-enabled httpd.service
systemctl disable httpd.service
systemctl is-enabled httpd.service
重啓服務進行訪問測試:
systemctl status httpd.service
systemctl restart httpd.service
systemctl stop httpd.service
systemctl status httpd.service
html