标签:out symlink web3 div 控制 share admin comm exe
yum安装后默认配置文件
1 ~]# cat /etc/httpd/conf/httpd.conf 2 ServerRoot "/etc/httpd" 3 Listen 80 4 Include conf.modules.d/*.conf 5 User apache 6 Group apache 7 ServerAdmin root@localhost 8 ServerName www.example.com:80 9 <Directory /> 10 AllowOverride none 11 Require all denied 12 </Directory> 13 DocumentRoot "/var/www/html" 14 <Directory "/var/www"> 15 AllowOverride None 16 Require all granted 17 </Directory> 18 <Directory "/var/www/html"> 19 Options Indexes FollowSymLinks 20 AllowOverride None 21 Require all granted 22 </Directory> 23 <IfModule dir_module> 24 DirectoryIndex index.html 25 </IfModule> 26 <Files ".ht*"> 27 Require all denied 28 </Files> 29 ErrorLog "logs/error_log" 30 LogLevel warn 31 <IfModule log_config_module> 32 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 33 LogFormat "%h %l %u %t \"%r\" %>s %b" common 34 <IfModule logio_module> 35 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio 36 </IfModule> 37 CustomLog "logs/access_log" combined 38 </IfModule> 39 <IfModule alias_module> 40 ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" 41 </IfModule> 42 <Directory "/var/www/cgi-bin"> 43 AllowOverride None 44 Options None 45 Require all granted 46 </Directory> 47 <IfModule mime_module> 48 TypesConfig /etc/mime.types 49 AddType application/x-compress .Z 50 AddType application/x-gzip .gz .tgz 51 AddType text/html .shtml 52 AddOutputFilter INCLUDES .shtml 53 </IfModule> 54 AddDefaultCharset UTF-8 55 <IfModule mime_magic_module> 56 MIMEMagicFile conf/magic 57 </IfModule> 58 EnableSendfile on 59 IncludeOptional conf.d/*.conf
配置格式:directive value;directive 不区分字符大小写;value 为路径时,是否区分大小写,取决于文件系统。
ServerTokens Major|Minor|Min[imal]|Prod[uctOnly]|OS|Full
ServerTokens Prod #建议关闭显示服务器版本号
Listen [ip:]port 省略ip表示本机所有IP都监听,至少要有一个监听,此指令可重复出现多次
Listen 80
Persistent Connection:连接建立,每个资源获取完成后不会断开连接,而是继续等待其它的请求完成,默认关闭持久连接
KeepAlive On #启用长连接功能
KeepAliveTimeout 15 #保持连接15秒
MaxKeepAliveRequests 100 #断开条件
~]# httpd -M |grep mpm
mpm_prefork_module (shared) #默认prefork处理模式
~]# vim /etc/httpd/conf.modules.d/00-mpm.conf #在此文件中配置使用那种处理模块
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
#LoadModule mpm_event_module modules/mod_mpm_event.so
配置指定实现模块加载格式: LoadModule <mod_name> <mod_path>
示例:
~]# vim /etc/httpd/conf.modules.d/00-base.conf
LoadModule auth_basic_module modules/mod_auth_basic.so
DocumentRoot "/path" 指向的路径为URL路径的起始位置
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Require all granted #授权可以访问
</Directory>
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
? 基于文件系统路径:
<Directory “/path"> #控制文件夹
...
</Directory>
<File “/path/file”> #控制指定文件
...
</File>
<FileMatch "PATTERN"> #支持正则表达式
...
</FileMatch>
? 基于URL路径:
<Location "">
...
</Location>
<LocationMatch "PATTERN">
...
</LocationMatch>
1)Options [+|-]option [[+|-]option] ... :后跟1个或多个以空白字符分隔的选项列表在选项前的 +,- 表示增加或删除指定选项,默认Options FollowSymlinks
2)AllowOverride All|None|directive-type [directive-type] ... :与访问控制相关的哪些指令可以放在指定目录下的.htaccess(由AccessFileName指定)文件中,覆盖之前的配置指令;只对<directory>语句有效
3)Order Deny,Allow :定义生效次序;写在后面的表示默认法则,2.4版本不再支持
例:拒绝访问站点下所有以.conf结尾的文件
DocumentRoot "/data/website"
<Directory "/data/website">
Require all granted
</Directory>
<Files "*.conf">
Require all denied
</Files>
? 例:允许访问符号链接文件所指向的源文件,但是不允许返回索引列表给用户
<Directory "/data/website">
Require all granted
Options -Indexes +FollowSymLinks
</Directory>
? 不允许指定的主机访问
DocumentRoot "/data/website"
<Directory "/data/website">
<RequireALL>
Require all granted
Require not ip 192.168.0.2 #不允许0.2的主机访问
</RequireALL>
</Directory>
? 只允许指定主机访问
DocumentRoot "/data/website"
<Directory "/data/website">
<RequireAny>
Require all denied
Require ip 192.168.0.2 #只允许0.2主机访问
</RequireAny>
</Directory>
~]# vim /etc/httpd/conf/httpd.conf
ErrorLog "logs/error_log" #错误日志记录文件
LogLevel warn #默认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>
错误日志的 LogLevel 可选:debug, info, notice, warn, error,crit, alert, emerg
访问日志:
建议:自定义日志记录格式
<IfModule log_config_module>
LogFormat "%h %l %u %{%F %T}t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" custlog
CustomLog "logs/access_log" custlog
</IfModule>
AddDefaultCharset utf-8 #设置默认字符集为utf-8,默认为AddDefaultCharset Off
<Directory "/data/website">
Require all granted
AddDefaultCharset utf-8
</Directory>
格式: Alias /URL/ "/PATH/"
Alias /web2 /data/website2
<Directory "/data/website2">
Require all granted
</Directory>
访问:http://192.168.0.7/web2
则是访问/data/website
这个目录下的站点
允许账号文件中的所有用户登录访问:Require valid-user
例:基于单用户认证
? 1)定义安全域
Alias /admin "/data/admin"
<Directory "/data/admin">
AuthType Basic
AuthName "please input your user and password!"
AuthUserFile "conf.d/.htuser"
Require user admin
</Directory>
? 2)提供账号和密码存储(文本文件)
~]# htpasswd -mc /etc/httpd/conf.d/.htuser admin
~]# cat /etc/httpd/conf.d/.htuser
admin:$apr1$Yfglmncl$BC1hebCpPjn1Sn.azt/Zu.
~]# systemctl restart httpd
? 3)测试访问 :http://192.168.0.7/admin/
,输入用户名密码即可访问
例:基于组账号进行认证
1)定义安全域
Alias /admin "/data/admin"
<Directory "/data/admin">
AuthType Basic
AuthName "please input your user and password!"
AuthUserFile "conf.d/.htuser"
AuthGroupFile "conf.d/.htgroup"
Require group gadmin gadmin2
</Directory>
2)提供账号和密码存储(文本文件)
~]# htpasswd -c /etc/httpd/conf.d/.htuser tom
~]# htpasswd /etc/httpd/conf.d/.htuser jerry
~]# htpasswd /etc/httpd/conf.d/.htuser maria
~]# echo ‘gadmin: tom jerry‘ > /etc/httpd/conf.d/.htgroup
~]# echo ‘gadmin2: tom maria‘ >> /etc/httpd/conf.d/.htgroup
3)测试访问 :http://192.168.0.7/admin/
,输入用户名密码即可访问
~]# vim /etc/httpd/conf.d/userdir.conf
<IfModule mod_userdir.c>
#UserDir disabled
UserDir public_html
</IfModule>
<Directory "/home/user1/public_html">
AuthType Basic
AuthName "user1 home dir"
AuthUserFile "conf.d/.htuser"
Require user user1
</Directory>
~]# htpasswd -c /etc/httpd/conf.d/.htuser user1
~]# systemctl restart httpd
~]# su -user1
~]$ mkdir public_html
~]$ echo "user1 home dir" > public_html/index.html
~]$ setfacl -m u:apache:x /home/user1/
访问:http://192.168.0.7/~user1/
站点,输入密码即可登录
? 当客户请求的网页并不存在时,服务器将产生错误文档,如果于打开了ServerSignature选项,错误文档的最后一行将包含服务器的名字、Apache的版本等信息;如果不对外显示这些信息,就可以将这个参数设置为Off;设置为Email,将显示ServerAdmin 的Email提示;2.4版本默认值关闭,2.2版本默认开启
LoadModule status_module modules/mod_status.so 确认此模块已加载
httpd]# vim conf.d/myhttp.conf
<Location "/status">
SetHandler server-status
Require all granted
</Location>
~]# systemctl restart httpd
访问http://192.168.0.7/status
查看服务器状态信息
注意:一般虚拟机不要与main主机混用;因此,要使用虚拟主机,一般先禁用main主机;注释中心主机的DocumentRoot指令即可。
2.4版本基于FQDN的虚拟主机不再需要NameVirutalHost指令
data]# mkdir website{1..3}
data]# echo ‘<h1>website 1</h1>‘ > website1/index.html
data]# echo ‘<h1>website 2</h1>‘ > website2/index.html
data]# echo ‘<h1>website 3</h1>‘ > website3/index.html
~]# vim /etc/httpd/conf/httpd.conf
#Listen 80
#DocumentRoot "/var/www/html"
三种实现方案:
~]# vim /etc/httpd/conf.d/virtualhost.conf
Listen 81
Listen 82
Listen 83
<Directory "/data">
Require all granted
</Directory>
<VirtualHost *:81>
DocumentRoot "/data/website1"
ServerName www.web1.com
ErrorLog "logs/web1_error_log"
TransferLog "logs/web1_access_log"
</VirtualHost>
<VirtualHost *:82>
DocumentRoot "/data/website2"
ServerName www.web2.com
ErrorLog "logs/web2_error_log"
TransferLog "logs/web2_access_log"
</VirtualHost>
<VirtualHost *:83>
DocumentRoot "/data/website3"
ServerName www.web3.com
ErrorLog "logs/web3_error_log"
TransferLog "logs/web3_access_log"
</VirtualHost>
~]# systemctl restart httpd
分别访问:
http://192.168.0.7:81
和http://192.168.0.7:82
和http://192.168.0.7:83
~]# ip a a 192.168.0.11/24 dev eth0
~]# ip a a 192.168.0.12/24 dev eth0
~]# ip a a 192.168.0.13/24 dev eth0
~]# vim /etc/httpd/conf.d/virtualhost.conf
Listen 80
<Directory "/data">
Require all granted
</Directory>
<VirtualHost 192.168.0.11:80>
DocumentRoot "/data/website1"
ServerName www.web1.com
ErrorLog "logs/web1_error_log"
TransferLog "logs/web1_access_log"
</VirtualHost>
<VirtualHost 192.168.0.12:80>
DocumentRoot "/data/website2"
ServerName www.web2.com
ErrorLog "logs/web2_error_log"
TransferLog "logs/web2_access_log"
</VirtualHost>
<VirtualHost 192.168.0.13:80>
DocumentRoot "/data/website3"
ServerName www.web3.com
ErrorLog "logs/web3_error_log"
TransferLog "logs/web3_access_log"
</VirtualHost>
~]# systemctl restart httpd
分别访问:
192.168.0.11
和192.168.0.12
和192.168.0.13
~]# vim /etc/httpd/conf.d/virtualhost.conf
Listen 80
<Directory "/data">
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot "/data/website1"
ServerName www.web1.com
ErrorLog "logs/web1_error_log"
TransferLog "logs/web1_access_log"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/website2"
ServerName news.web2.com
ErrorLog "logs/web2_error_log"
TransferLog "logs/web2_access_log"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/website3"
ServerName bbs.web3.com
ErrorLog "logs/web3_error_log"
TransferLog "logs/web3_access_log"
</VirtualHost>
~]# systemctl restart httpd
客户端测试:
~]# vim /etc/hosts 添加以下内容 192.168.0.7 www.web1.com news.web2.com bbs.web3.com ~]# curl www.web1.com ~]# curl news.web2.com ~]# curl bbs.web3.com
LoadModule deflate_module modules/mod_deflate.so 模块默认已经加载
# httpd -M |grep deflate
deflate_module (shared)
conf.d]# vim myhttpd.conf
# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
DeflateCompressionLevel 9 #压缩比为 9
~]# vim /etc/httpd/conf/httpd.conf
EnableSendfile On
标签:out symlink web3 div 控制 share admin comm exe
原文地址:https://www.cnblogs.com/Gmiaomiao/p/9220813.html