天天看点

apache userdir功能

userdir模块可以很方便的和他人共享服务器的目录资料

该功能需要修改此配置文件

/etc/httpd/conf.d/userdir.conf

<IfModule mod_userdir.c>

#

# UserDir is disabled by default since it can confirm the presence

# of a username on the system (depending on home directory

# permissions).

# UserDir disabled   ###########注释掉改参数,即等于开始userdir功能

# To enable requests to /~user/ to serve the user's public_html

# directory, remove the "UserDir disabled" line above, and uncomment

# the following line instead:

  UserDir public_html       ############## 打开

</IfModule> 

#共享目录的权限设置如下

<Directory "/home/*/public_html">

# AllowOverride FileInfo AuthConfig Limit Indexes

AllowOverride all

#添加一些认证的配置,可以用账号,密码访问该目录

authuserfile "/etc/htttpd/passwd"

authname "input your accout"

authtype basic

require user jay

# Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

# Require method GET POST OPTIONS

</Directory>

创建网站资料,注意权限的问题

使用普通用户,创建共享目录

useradd jay

su - root

mkdir  public_html  #创建共享目录

apache userdir功能

设置该目录权限

chmod -Rf 755 /public_html/index.html

apache userdir功能

创建阿帕奇的用户认证文件,注意退回到root

[root@localhost ~]# htpasswd -c /etc/httpd/

conf/ conf.d/ conf.modules.d/ logs/ modules/ run/

[root@localhost ~]# htpasswd -c /etc/httpd/passwd jay

New password:

Re-type new password:

Adding password for user jay

重启apache,注意修改httpd的端口 80

systemctl restart httpd

此时访问 http:ip/~用户家目录名 

输入账号密码

虚拟主机

如果web server不支持多虚拟主机

用户有多个业务网站,就得购买多台服务器,造成资源浪费,成本较高 

apache userdir功能

  虚拟主机,也称作,网站空间:

其实就是一台运行在互联网中的服务器,被划分为多个"虚拟"服务器

apache userdir功能
apache userdir功能

 基于ip的多虚拟主机

apache userdir功能
apache userdir功能
apache userdir功能
apache userdir功能

 配置apache的主配置文件,定义多个虚拟 主机

apache userdir功能

 重启apache服务,加载配置

访问

apache userdir功能

总结

配置了apache的多虚拟主机功能。

在httpd.conf中定义了2个虚拟主机