DocumentRoot "/data/www/html"##文档路径映射,路径为url的起始路径 <Directory "/data/www">
Require all granted
</Directory>[root@localhost html]# pwd
/data/www/html
[root@localhost html]# tree ..
├── index.html
└── news
└── index.html
1 directory, 2 files
[root@vm1 ~]# curl 192.168.1.222
/data/www/html/index.html
[root@vm1 ~]# curl 192.168.1.222/news/index.html
this is news
[root@localhost conf.d]# ll
total 20
-rw-r--r-- 1 root root 2926 Nov 17 00:18 autoindex.conf
-rw-r--r-- 1 root root 366 Nov 17 00:19 README
-rw-r--r-- 1 root root 110 Apr 16 00:40 test.conf
-rw-r--r-- 1 root root 1252 Nov 16 22:44 userdir.conf
-rw-r--r-- 1 root root 824 Nov 16 22:44 welcome.conf
[root@localhost conf.d]# cat welcome.conf # # This configuration file enables the default "Welcome" page if there# is no default index page present for the root URL. To disable the# Welcome page, comment out all the lines below. ## NOTE: if this file is removed, it will be restored on upgrades.#<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch><Directory /usr/share/httpd/noindex>
AllowOverride None
Require all granted
</Directory>
Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
##实现http://192.168.1.222/download/访问映射到服务器上面/main/soft/,不仅可以使用软连接,还能使用alias映射,步骤如下#步骤1:在配置文件中添加如下:[root@localhost conf.d] vim /etc/httpd/conf.d/test.conf
alias /download/ /main/soft/
<Directory "/main/soft">
Options Indexes
Require all granted ##授权1</Directory>##步骤2:chmod 755 /main/soft使得其他人(apache用户)有权限访问 ##授权2
#实现访问的根目录在/data/www/html#ip控制访问,拒绝192.168.1.222该地址的访问#以.conf结尾的文件禁止所有人访问[root@localhost conf.d] vim /etc/httpd/conf.d/test.conf
DocumentRoot "/data/www/html"<Directory "/data/www/html">
Options Indexes
AllowOverride all ##AllowOverride 表示.htaccess可以重写配置
Require all granted
</Directory>[root@localhost html]# vim /data/www/html/.htaccess <requireall>
require all granted
require not ip 192.168.1.223
</requireall><files "*.conf">
require all denied
</files>
##实现状态页面,仅允许192.168.1.105访问[root@localhost private]# httpd -M | grep status
status_module (shared)[root@localhost html]# vim /etc/httpd/conf.d/test.conf<Location "/status">#Location表示http请求的命令。而不是文件夹
sethandler server-status
<requireany>
require all denied
require ip 192.168.1.105
</requireany></Location>
#实现ymsk家目录共享给所有人[root@localhost private]# httpd -M | grep user
userdir_module (shared)[root@localhost private]# setfacl -m u:apache:x /home/ymsk/ ##apache进入ymsk家目录需要添加x权限[root@localhost home]# ll -d /home/ymsk/
drwx--x---+ 6 ymsk ymsk 4096 Apr 16 18:34 /home/ymsk/
[root@localhost home]# vim /etc/httpd/conf.d/userdir.conf# UserDir: The name of the directory that is appended onto a user's home# directory if a ~user request is received.## The path to the end user account 'public_html' directory must be# accessible to the webserver userid. This usually means that ~userid# must have permissions of 711, ~userid/public_html must have permissions# of 755, and documents contained therein must be world-readable.# Otherwise, the client will only receive a "403 Forbidden" message.#<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## 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>## Control access to UserDir directories. The following is an example# for a site where these directories are restricted to read-only.##<Directory "/home/*/public_html"># AllowOverride FileInfo AuthConfig Limit Indexes# Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec# Require method GET POST OPTIONS#</Directory><Directory "/home/ymsk/public_html">
Options Indexes
AllowOverride all
Require all granted
</Directory>##浏览器访问http://192.168.1.222/~ymsk/