一.基于虚拟目录和用户控制的 web 网站
首先进入/usr/local/路径下,创建一个目录,用于存放密码文件。
1.创建一个目录,存放密码文件
[root@localhost local]# mkdir passwddir
[root@localhost local]# ls
bin etc games include lib lib64 libexec passwddir sbin share src
[root@localhost local]#
为httpuser1用户创建密码,密码为user1
[root@localhost local]# htpasswd -c /usr/local/passwddir/password httpuser1
New password:
Re-type new password:
Adding password for user httpuser1
[root@localhost local]#
2.切换到/www/路径下,创建一个userctl目录,
[root@localhost local]# cd /www
[root@localhost local]# mkdir userctl
[root@localhost www]# ls
cgi https ip name port userctl
然后将访问的内容编写到userctl中的index.html文件中
[root@localhost www]# echo "this is my user" > /www/userctl/index.html
[root@localhost www]#
3.切换到/etc/httpd/conf.d路径下
[root@localhost conf.d]# ls
autoindex.conf myhost2.conf myhost.conf myssl.conf README ssl.conf userdir.conf welcome.conf
[root@localhost conf.d]#
在myhost.conf中编辑配置文件
<Directory "/www/userctl">
AuthType Basic
AuthName "Welcome"
AuthBasicProvider file
AuthUserFile "/usr/local/passwddir/password"
Require user httpuser1
</Directory>
Listen 8005
<VirtualHost 192.168.179.131:8005>
DocumentRoot "/www/userctl"
ServerName 192.168.179.131
</VirtualHost>
重启服务
[root@localhost conf.d]# systemctl restart httpd
[root@localhost conf.d]#
使用网页访问ip
输入用户名httpuser1,密码user1
访问成功
二.网站和配置访问apache的cgi
1.首先进入到/www/路径下
创建目录名为cgi
root@localhost www]# mkdir cgi
[root@localhost www]# ls
cgi https ip name port userctl
2.再进入到cgi目录,创建test.cgi(后缀要.cgi)文件,编写shell脚本,保存退出
[root@localhost www]# cd cgi
[root@localhost www]vim test.cgi
#/bin/bash
printf "Content-Type:text/html\n\n"
printf "Hello,Word"
3.进入/etc/httpd/conf.d路径下,再myhost.conf中配置
<Directory "/www/cgi">
AllowOverride None
options +ExecCGI
AddHandler cgi-script .cgi
Require all granted
</Directory>
Listen 9000
<VirtualHost 192.168.179.131:9000>
DocumentRoot "/www/cgi"
#ScriptAlias / /www/cgi
ServerName 192.168.179.131
</VirtualHost>
4.重启服务
[root@localhost conf.d]# systemctl restart httpd
[root@localhost conf.d]#
5.访问ip
访问成功,
如果网页报错,切换到/www/cgi路径下,查看文件的权限,查看有没有执行权限
[root@localhost cgi]# ll
total 4
-rwxr-xr-x. 1 root root 68 Dec 14 06:42 test.cgi
如果没有执行权限需要加上执行权限(本图有执行权限)
[root@localhost cgi]# chmod +x test.cgi
[root@localhost cgi]#
然后再去访问网页就会成功