PHP Advanced and Object-Oriented Programming
Larry Ullman
The standard solution in these situations is to use the Apache Web server’s mod_rewrite module to allow for “prettier” URLs. mod_rewrite is a tool that lets you instruct the server that when the user goes to one URL, the server should provide another resource. mod_rewrite makes use of regular expressions, so the matching pattern and resulting actual URL can be as complex as needed.
These, and other changes to Apache’s behavior, can be made in two ways: by editing the primary Apache configuration file or by creating directory-specific files. The primary configuration file is httpd.conf, found within a conf directory, and it dictates how the entire Apache Web server runs (where the httpd.conf file is on your system will depend on many things). An .htaccess
file (pronounced “H-T access”) is placed within a Web directory and is used to affect how Apache behaves within just that folder and subfolders.
Generally speaking, it’s preferable to make changes in the httpd.conf file, since this file needs to be read only by the Web server each time the server is started. Conversely, .htaccess files must be read by the Web server once for every request to which an .htaccess file might apply.
 
 
 

[Sun Jan 07 20:42:16.394102 2018] [rewrite:error] [pid 188:tid 2172] [client 192.168.2.102:51806] AH00670: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions : C:/phpStudy/PHPTutorial/WWW/fastdatav/
[Sun Jan 07 20:52:22.419296 2018] [rewrite:error] [pid 188:tid 2172] [client 192.168.2.102:52530] AH00670: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions : C:/phpStudy/PHPTutorial/WWW/fastdatav/
<IfModule dir_module>
DirectoryIndex index.html index.php index.htm l.php
</IfModule>

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
DocumentRoot "C:\phpStudy\PHPTutorial\WWW"
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
+Indexes 表示允许对目录文件生成列表
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
# #
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
# #
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html index.php index.htm l.php
</IfModule>
按照顺序,有index.php l.php同时有时,执行index.php #
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ".ht*">
Require all denied
</Files>
http://192.168.2.102/.htmy
You don't have permission to access /.htmy on this server. http://192.168.2.102/.mytxt
显示.mytxt文本内容
#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
日志位置
#ErrorLog "logs/error.log"
#ErrorLog "|bin/rotatelogs.exe -l logs/error-%Y-%m-%d.log 2M" #
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
日志记录级别
LogLevel debug <IfModule log_config_module>
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# 日志记录格式 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>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule> #
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here. Contrariwise, if you *do*
# define per-<VirtualHost> access logfiles, transactions will be
# logged therein and *not* in this file.
#
##CustomLog "logs/access.log" common #
# If you prefer a logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#
#CustomLog "logs/access.log" combined
</IfModule>

Apache的Order Allow,Deny 详解

Allow和Deny可以用于apache的conf文件或者.htaccess文件中(配合Directory, Location, Files等),用来控制目录和文件的访问授权。

所以,最常用的是:
Order Deny,Allow
Allow from All

注意“Deny,Allow”中间只有一个逗号,也只能有一个逗号,有空格都会出错;单词的大小写不限。上面设定的含义是先设定“先检查禁止设定,没有禁止的全部允许”,而第二句没有Deny,也就是没有禁止访问的设定,直接就是允许所有访问了。这个主要是用来确保或者覆盖上级目录的设置,开放所有内容的访问权。

按照上面的解释,下面的设定是无条件禁止访问:
Order Allow,Deny
Deny from All

如果要禁止部分内容的访问,其他的全部开放:
Order Deny,Allow
Deny from ip1 ip2
或者
Order Allow,Deny
Allow from all
Deny from ip1 ip2

apache会按照order决定最后使用哪一条规则,比如上面的第二种方式,虽然第二句allow允许了访问,但由于在order中allow不是最后规则,因此还需要看有没有deny规则,于是到了第三句,符合ip1和ip2的访问就被禁止了。注意,order决定的“最后”规则非常重要,下面是两个错误的例子和改正方式:

Order Deny,Allow
Allow from all
Deny from domain.org
错误:想禁止来自domain.org的访问,但是deny不是最后规则,apache在处理到第二句allow的时候就已经匹配成功,根本就不会去看第三句。
解决方法:Order Allow,Deny,后面两句不动,即可。

Order Allow,Deny
Allow from ip1
Deny from all
错误:想只允许来自ip1的访问,但是,虽然第二句中设定了allow规则,由于order中deny在后,所以会以第三句deny为准,而第三句的范围中又明显包含了ip1(all include ip1),所以所有的访问都被禁止了。
解决方法一:直接去掉第三句。
解决方法二:
Order Deny,Allow
Deny from all
Allow from ip1

下面是测试过的例子:
--------------------------------
Order deny,allow
allow from all
deny from 219.204.253.8
#全部都可以通行
-------------------------------
Order deny,allow
deny from 219.204.253.8
allow from all
#全部都可以通行
-------------------------------
Order allow,deny
deny from 219.204.253.8
allow from all
#只有219.204.253.8不能通行
-------------------------------
Order allow,deny
allow from all
deny from 219.204.253.8
#只有219.204.253.8不能通行
-------------------------------
-------------------------------
Order allow,deny
deny from all
allow from 219.204.253.8
#全部都不能通行 
-------------------------------
Order allow,deny
allow from 219.204.253.8
deny from all
#全部都不能通行

 
 
 
 
 
在根目录加入
.htaccess文件
Options +FollowSymLinks
 

httpd.conf .htaccess apache 服务器配置的更多相关文章

  1. Php和httpd.conf的配置

    http://www.cnblogs.com/homezzm/archive/2012/08/01/2618062.html http://book.51cto.com/art/201309/4096 ...

  2. Apache 的 httpd.conf 注释

    ServerRoot “/usr/local“ ServerRoot用于指定守护进程httpd的运行目录,httpd在启动之后将自动将进程的当前目录改变为这个目录,因此如果设置文件中指定的文件或目录是 ...

  3. Apache httpd.conf配置文件 2(Main server configuration)

    ### Section 2: 'Main' server configuration # # The directives in this section set up the values used ...

  4. Apache主配置文件httpd.conf 详解

    Apache的主配置文件:/etc/httpd/conf/httpd.conf 默认站点主目录:/var/www/html/ Apache服务器的配置信息全部存储在主配置文件/etc/httpd/co ...

  5. 关于apache httpd.conf脚本的理解

    新人一枚,这两天一直在研究lamp的搭建,感觉自己对apache理解的不够深彻,决定写这一篇(翻译)httpd.conf文件 未完待续 cat /usr/local/apache/conf/httpd ...

  6. Apache 的 httpd.conf 详解

    ServerRoot “/usr/local“ ServerRoot用于指定守护进程httpd的运行目录,httpd在启动之后将自动将进程的当前目录改变为这个目录,因此如果设置文件中指定的文件或目录是 ...

  7. Apache配置文件httpd.conf内容翻译

      本文已经废弃,现在apache2不依靠httpd.conf来配置. Ubuntu下默认的配置文件是/etc/apache2/sites-available/default 可以修改上面文件来修改a ...

  8. linux上安装apache以及httpd.conf基本配置

    1.yum安装apache #yum install httpd -y 2.随系统自启动 #chkconfig httpd on 3.开启apache #service httpd start PS: ...

  9. Apache的配置httpd.conf文件配置

    (1) 基本配置: ServerRoot "/mnt/software/apache2" #你的apache软件安装的位置.其它指定的目录如果没有指定绝对路径,则目录是相对于该目录 ...

随机推荐

  1. 使用 redis “捕捉” “用户登录过期” 事件

    实现原理及步骤: 1)登录时,计算登录过期时间,以分钟为单位作key(例如:sign_timeout_201705212233),value方面自己发挥,需要什么数据就拼什么数据进去,只是要注意,一定 ...

  2. Django 创建第一个项目

    创建项目: [root@localhost ~]$ django-admin.py startproject web # web是项目名 [root@localhost ~]$ tree web/ w ...

  3. Jar命令

    JAR包是Java中所特有一种压缩文档,其实大家就可以把它理解为.zip包;当然也是有区别的,JAR包中有一个META-INF\MANIFEST.MF文件,当你打成JAR包时,它会自动生成. 一.ja ...

  4. ida+windbg调试windows

    jpg 改 pdf https://www.hex-rays.com/products/ida/support/tutorials/debugging_windbg.pdf

  5. USACO The Clocks

    操作间没有次序关系,同一个操作最多重复3次... 可以直接暴力... The Clocks IOI'94 - Day 2 Consider nine clocks arranged in a 3x3 ...

  6. Nginx反向代理腾讯云COS的一个坑

    版权声明:本文由黄希彤   原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/668639001484812620 来源:腾云 ...

  7. adb 查看内存信息的命令

    meminfo: basic memory status-adb shell cat proc/meminfo  -- 内存系统信息-adb shell cat proc/pid/maps --  指 ...

  8. 跟我一起写Makefile:使用函数

    跟我一起写Makefile:使用函数 两个排版不一样 书籍下载 书籍下载

  9. github上打包的样式为什么在预览的时候,出现404

    这是资源引用的问题 在这里主要是需要在dist的index.html文件内将"./static/css/style.css"改为"static/css/style.css ...

  10. openstack-networking-neutron(三)---用户态和内核态的区别

    究竟什么是用户态,什么是内核态,这两个基本概念以前一直理解得不是很清楚,根本原因个人觉得是在于因为大部分时候我们在写程序时关注的重点和着眼的角度放在了实现的功能和代码的逻辑性上,先看一个例子: 1)例 ...