1, the configuration file description
1.1 The main configuration file directory
vi /etc/httpd/conf/httpd.conf
1.2 Configuration File Format
# directive 指令 value 值
ServerRoot "/etc/httpd"
ServerRoot path for the root apache services, generally do not modify.
2. Detailed configuration items
2.1 ServerRoot
Service directory path, no changes are
ServerRoot "/etc/httpd"
2.2 Listen
Listening port
#Listen 12.34.56.78:80
Listen 80
Configuration syntax
Listen [IP-address:]portnumber [protocol]
usage scenarios
the default listener port 80, or browser access to 127.0.0.1 localhost or server ip can get the default welcome page.
You can also listen on multiple ports simultaneously.
practice
# 1. 修改端口号
Listen 8080
# 2. Listen指令可重复出现多次
Listen 8080
Listen 80
# 注意:修改后必须重启服务才可生效
[root@localhost conf]# systemctl restart httpd.service
2.3 Include
Import Profiles
Include conf.modules.d/*.conf
2.4 IncludeOptional
And include the same features, are imported profile. The difference is when the path is ignored IncludeOptional import problems. Without error.
IncludeOptional conf.d/*.conf
2.5 User和Group
Accounts and groups of service httpd child process started, this need not be amended
User apache
Group apache
2.6 ServerAdmin
Administrator e-mail address of runtime services
ServerAdmin root@localhost
2.7 DocumentRoot
Site root directory
in this folder decentralized data
DocumentRoot "/var/www/html"
grammar
DocumentRoot directory-path
practice
#DocumentRoot "/var/www/html"
DocumentRoot "/www"
#<Directory "/var/www/html">
<Directory "/www">
2.8 Directory
Determining the location of access directory, configuration label. It is set access permissions for that directory in the tag
<Directory "/var/www/html">
Options Indexes FollowSymLinks # 访问时的展示形式,Indexes索引展示
AllowOverride None # 设置指令是否可以在.htaccess使用
Require all granted # 允许所有人访问
</Directory>
Options display format when access
There is no default page under Options Indexes current directory, it displays the directory structure
Options FollowSymLinks default settings to allow access to the symbolic link
Options None shut down
under normal circumstances would Indexes off, do not want others to see what files in site directory, only time will do the download site open. The default is on.
AllowOverride
.htaccess
file allows instruction typeAll AllowOverride All command
AllowOverride None default value is not allowed
AllowOverride directive-type [directive-type] ... particular instruction type
Require access settings
Require all granted unconditionally allow access
Require all denied unconditionally denied access
Require method http-method ** [** http-method] ... allow only given access HTTP methods
Require ip 10 172.20 192.168.2 specify the ip address range of clients can access
practice
# 1. 去掉Indexes查看效果,注意改完配置后要重启http服务
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
# 2. 去掉FollowSymLinks
<Directory "/var/www/html">
Options None
AllowOverride None
Require all granted
</Directory>
# 3. 使用Require
<Directory "/var/www/html">
Options None
AllowOverride None
Require all denied # 无条件拒绝访问
</Directory>
<Directory "/var/www/html">
Options None
AllowOverride None
Require method POST # 仅允许post请求
</Directory>