httpd常见配置

[root@localhost httpd]# cat /etc/httpd/conf/httpd.conf  | egrep  -v "#|^$"
ServerRoot "/etc/httpd"                                       ##httpd服务器的根目录
Listen 80
User apache
Group apache
ServerAdmin root@localhost

<Directory />
    AllowOverride none                                    	#AllowOverride表示在具体目录下配置.htaccess知否可以重写原有配置
    Require all denied										#来自客户端的请求全部拒绝
</Directory>

DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<IfModule dir_module>                                             #默认展示index.html
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">       #.htaccess可以放置在数据所在的文件夹里面,而不是配置在配置文件里面,但.ht隐藏文件禁止通过http访问
    Require all denied   
</Files>

ErrorLog "logs/error_log"
LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on
IncludeOptional conf.d/*.conf
Include conf.modules.d/*.conf
ServerRoot "/etc/httpd"   											
[root@localhost httpd]# pwd
/etc/httpd
[root@local	host httpd]# ll
total 12
drwxr-xr-x 2 root root 4096 Apr 15 23:33 conf            			##配置文件
drwxr-xr-x 2 root root 4096 Apr 15 22:00 conf.d           			##用户自定义配置文件,以*.conf该形式引入
drwxr-xr-x 2 root root 4096 Apr 15 22:42 conf.modules.d  		 	##静态以及动态模块加载的配置文件
lrwxrwxrwx 1 root root   19 Apr 15 21:33 logs -> ../../var/log/httpd
lrwxrwxrwx 1 root root   29 Apr 15 21:33 modules -> ../../usr/lib64/httpd/modules    ##模块
lrwxrwxrwx 1 root root   10 Apr 15 21:33 run -> /run/httpd
servertokens 		(productOnly,只展示产品,不展示版本)	


[root@localhost conf.d]# curl -I 192.168.1.222
HTTP/1.1 200 OK
Date: Thu, 15 Apr 2021 15:40:42 GMT
Server: Apache/2.4.6 (CentOS)   							##展示版本以及系统
Last-Modified: Thu, 15 Apr 2021 13:54:37 GMT
ETag: "3-5c003343ce404"
Accept-Ranges: bytes
Content-Length: 3
Content-Type: text/html; charset=UTF-8


[root@localhost conf.d]# curl -I 192.168.1.222
HTTP/1.1 200 OK
Date: Thu, 15 Apr 2021 15:42:03 GMT
Server: Apache   											##展示产品	
Last-Modified: Thu, 15 Apr 2021 13:54:37 GMT
ETag: "3-5c003343ce404"
Accept-Ranges: bytes
Content-Length: 3
Content-Type: text/html; charset=UTF-8

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
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

#将DocumentRoot 下的index.html及conf.d/welcome.conf删掉,就会实现展示DocumentRoot 目录下的索引结构(包含该目录下的符号链接文件)
#通过Indexes 以及 FollowSymLinks实现



##实现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>

#实现basic用户登录
# user:bob  jhon   密码123456 
[root@localhost soft]# httpd -M | grep auth_basic_module
	auth_basic_module (shared)
[root@localhost html]# htpasswd -c /data/www/html/private/.httpuser jhon 
[root@localhost html]# htpasswd  /data/www/html/private/.httpuser bob    ##-c参数后面不能加
	
[root@localhost html]# vim /etc/httpd/conf.d/test.conf
<Directory "/data/www/html/private/">
AllowOverride authconfig
</Directory>

[root@localhost private]# vim /data/www/html/private/.htaccess 
authtype basic
authname "admin-page"                   ##网页展示字段
authuserfile "/etc/httpd/conf.d/.httpuser"
require valid-user                      ##所有在.httpuser文件中的都是合法用户,authgroupfile指令也可以使用户分组后按组控制访问
##实现状态页面,仅允许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/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值