设为首页 收藏本站
查看: 744|回复: 0

[经验分享] apache的常用配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-5-6 08:27:26 | 显示全部楼层 |阅读模式
域名跳转
[iyunv@localhost ~]# vi  /usr/local/apache2/conf/extra/httpd-vhosts.conf

*************************************

<IfModule mod_rewrite.c>
         RewriteEngine on
         RewriteCond %{HTTP_HOST} ^www.aaa.com$ [OR]//注意空格
         RewriteCond %{HTTP_HOST} ^www.bbb.com$
         RewriteRule ^/(.*)$ http://www.123.com/$1 [R=301,L]
     </IfModule>
或者:    <IfModule mod_rewrite.c>
                 RewriteEngine on
                 RewriteCond %{HTTP_HOST} !^www.123.com$//注意空格
                 RewriteRule ^/(.*)$ http://www.123.com/$1 [R=301,L]
      </IfModule>
************************

[ ~]# curl -x127.0.0.1:80 -I
HTTP/1.1 301 Moved Permanently
Date: Tue, 05 May 2015 18:40:12 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
X-Powered-By: PHP/5.3.28
location: forum.php
Cache-Control: max-age=0
Expires: Tue, 05 May 2015 18:40:12 GMT
Content-Type: text/html

[ ~]# curl -x127.0.0.1:80 -I
HTTP/1.1 301 Moved Permanently
Date: Tue, 05 May 2015 18:40:21 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Location:
Cache-Control: max-age=0
Expires: Tue, 05 May 2015 18:40:21 GMT
Content-Type: text/html; charset=iso-8859-1

[ ~]# curl -x127.0.0.1:80 -I
HTTP/1.1 301 Moved Permanently
Date: Tue, 05 May 2015 18:40:28 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Location:
Cache-Control: max-age=0
Expires: Tue, 05 May 2015 18:40:28 GMT
Content-Type: text/html; charset=iso-8859-1


配置静态文件缓存

[iyunv@localhost ~]# vi  /usr/local/apache2/conf/extra/httpd-vhosts.conf


<Ifmodule mod_headers.c>
<filesmatch "\.(html|htm|txt)$">
header set cache-control "max-age=3600"
</filesmatch>
<filesmatch "\.(css|js|swf)$">
header set cache-control "max-age=604800"
</filesmatch>
<filesmatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$">
header set cache-control "max-age=29030400"
</filesmatch>
</ifmodule>

[ ~]# curl -x127.0.0.1:80 -I
HTTP/1.1 200 OK
Date: Tue, 05 May 2015 18:59:19 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Last-Modified: Fri, 26 Dec 2014 01:49:42 GMT
ETag: "22a88-25b-50b14bd049980"
Accept-Ranges: bytes
Content-Length: 603
cache-control: max-age=604800
Content-Type: application/javascript


配置访问控制

[iyunv@localhost ~]# vi  /usr/local/apache2/conf/extra/httpd-vhosts.conf

<Directory /data/
[url=]www/>[/url]

    <filesmatch ".*">
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </filesmatch>
</Directory>


[root@localhost ~]# curl -x192.168.1.110:80 www.123.com/1.txt -I
HTTP/1.1 403 Forbidden
Date: Tue, 05 May 2015 19:17:26 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Content-Type: text/html; charset=iso-8859-1
[root@localhost ~]# curl -x127.0.0.1:80 www.123.com/1.txt -I
HTTP/1.1 200 OK
Date: Tue, 05 May 2015 19:18:49 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Last-Modified: Sat, 02 May 2015 15:22:31 GMT
ETag: "2325b-a-5151ae5c57002"
Accept-Ranges: bytes
Content-Length: 10
cache-control: max-age=3600
Content-Type: text/plain
这样配置会导致不能访问网站,在工作中是不允许的,一般应用于禁止访问网站的重要目录。

禁止访问某个目录:

[iyunv@localhost ~]# vi  /usr/local/apache2/conf/extra/httpd-vhosts.conf

<Directory /data/
[url=]www/admin/>[/url]

    <filesmatch ".*">

        Order deny,allow

        Deny from all

        Allow from 127.0.0.1

    </filesmatch>

    </Directory>


[root@localhost ~]# curl -x127.0.0.1:80 www.123.com/admin/1.txt -I  //没有创建目录及文件导致错误
HTTP/1.1 404 Not Found
Date: Tue, 05 May 2015 19:23:04 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Content-Type: text/html; charset=iso-8859-1
[root@localhost ~]# mkdir /data/[url=]www/admin/[/url]
[root@localhost ~]# touch /data/[url=]www/admin[/url]/1.txt
[root@localhost ~]# curl -x127.0.0.1:80 www.123.com/admin/1.txt -I
HTTP/1.1 200 OK
Date: Tue, 05 May 2015 19:24:08 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Last-Modified: Tue, 05 May 2015 19:24:06 GMT
ETag: "2325e-0-5155a9f3c2ff5"
Accept-Ranges: bytes
cache-control: max-age=3600
Content-Type: text/plain
X-Pad: avoid browser bug

[root@localhost ~]# curl -x192.168.1.110:80 www.123.com/admin/1.txt -I
HTTP/1.1 403 Forbidden
Date: Tue, 05 May 2015 19:24:23 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Content-Type: text/html; charset=iso-8859-1


禁止访问某个文件
[iyunv@localhost ~]# vi  /usr/local/apache2/conf/extra/httpd-vhosts.conf
    <Directory /data/[url=]www/>[/url]
    <filesmatch "^admin.php(.*)$">
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </filesmatch>
    </Directory>
[root@localhost ~]# curl -x192.168.1.110:80 www.123.com/admin.phpsfsafa -I
HTTP/1.1 403 Forbidden
Date: Tue, 05 May 2015 20:12:46 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Content-Type: text/html; charset=iso-8859-1
[root@localhost ~]# curl -x192.168.1.110:80 www.123.com/admin.php -I
HTTP/1.1 403 Forbidden
Date: Tue, 05 May 2015 20:15:35 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Content-Type: text/html; charset=iso-8859-1
[root@localhost ~]# curl -x127.0.0.1:80 www.123.com/admin.php -I
HTTP/1.1 200 OK
Date: Tue, 05 May 2015 20:15:58 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
X-Powered-By: PHP/5.3.28
*******
Content-Type: text/html; charset=gbk

限制php解析

[iyunv@localhost ~]# vi  /usr/local/apache2/conf/extra/httpd-vhosts.conf
<Directory /data/[url=]www/path>[/url]
      php_admin_flag engine off
       <filesmatch "(.*)php">
        Order deny,allow
        Deny from all
      </filesmatch>
</Directory>
[root@localhost # curl -x192.168.1.110:80 'http://www.123.com/path/1.php'
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /path/1.php
on this server.</p>
</body></html>
discuz伪静态配置:

首先在论坛后台的管理中心选择全局-->SEO设置-->URL 静态化选项上全部点勾-->提交
<IfModule mod_rewrite.c>

           RewriteEngine on
           RewriteCond %{HTTP_HOST} ^www.aaa.com$ [OR]
           RewriteCond %{HTTP_HOST} ^www.bbb.com$
           RewriteRule ^/(.*)$ http://www.123.com/$1 [R=301,L]
           RewriteCond %{QUERY_STRING} ^(.*)$
           RewriteRule ^/topic-(.+)\.html$ /portal.php?mod=topic&topic=$1&%1
           RewriteCond %{QUERY_STRING} ^(.*)$
           RewriteRule ^/article-([0-9]+)-([0-9]+)\.html$ /portal.php?mod=view&aid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/forum-(\w+)-([0-9]+)\.html$ /forum.php?mod=forumdisplay&fid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/group-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=group&fid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/space-(username|uid)-(.+)\.html$ /home.php?mod=space&$1=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/blog-([0-9]+)-([0-9]+)\.html$ /home.php?mod=space&uid=$1&do=blog&id=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/archiver/(fid|tid)-([0-9]+)\.html$ /archiver/index.php?action=$1&value=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ /plugin.php?id=$1:$2&%1
    </IfModule>




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-63973-1-1.html 上篇帖子: Apache配置用户认证、域名跳转、日志轮询、静态文件缓存、防盗链 下篇帖子: apache以mod_jk方式实现tomcat的负载均衡集群
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表