基于虚拟目录和用户控制的 web 网站和配置访问apache的cgi

一.基于虚拟目录和用户控制的 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]# 

然后再去访问网页就会成功

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值