apache的相關配置

來源:互聯網
上載者:User

標籤:apache的相關配置

1.apache使用者認證

cd /data/www/abc

touch 12.txt

cp /etc/passwd /data/www.abc/12.txt

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

   <Directory  /data/www/abc>

      Allowoverride AuthConfig

      Authname "自訂"

      AuthType  Basic

      AuthUserFile /data/.htpasswd

      require valid-user

    </Directory>

vim /etc/profile.d/path.sh

 /usr/local/apache/bin

!source 

htpasswd -c /data/.htpasswd user1(建立第二個使用者的時候不加參數)

apachectl -t

apachectl graceful

2.預設虛擬機器主機

cd /tmp/123

chmod 600 /tmp/123

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

 <VirtualHost *:80>

   DocumentRoot "/tmp/123"

   ServerName 1111.com

 </VirtualHost>

3.網域名稱301跳轉

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

   <IfModule mod_rewrite.c>

     RewriteEngine on

     RewriteCond %{HTTP_HOST} ^www.aaa.com$

     RewriteRule ^/(.*)$ http://www.test.com/$1 [R=301,L]

   </IfModule>

apachectl -t

apachectl restart

4.apache日誌切割(/usr/local/apache/logs)

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

開啟和修改

    ErrorLog "logs/test.com-error_log"

    CustomLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/test.com-access_%Y%m%d_log 86400" combined

5.apache不記錄指定檔案類型日誌

 vim /usr/local/apache/conf/extra/httpd-vhosts.conf

    SetEnvIf Request_URI ".*\.gif$" image-request

    SetEnvIf Request_URI ".*\.jpg$" image-request

    SetEnvIf Request_URI ".*\.png$" image-request

    SetEnvIf Request_URI ".*\.swf$" image-request

    SetEnvIf Request_URI ".*\.js$" image-request

    SetEnvIf Request_URI ".*\.css$" image-request

env=!image-request

apachectl -t

apachectl restart

apachectl graceful

6.apache配置靜態緩衝

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

  <ifModule mod_expires.c>

  ExpiresActive on

  ExpiresByType image/gif "access plus 1 days"

  ExpiresByType image/jpeg "access plus 24 hours"

  ExpiresByType image/png "access plus 1 days"

  ExpiresByType text/css "now plus 2 hours"

  ExpiresByType application/x-javascript "now plus 2 hours"

  ExpiresByType application/javascript "now plus 2 hours"

  ExpiresByType application/x-shockwave-flash "now plus 2 hours"

  ExpiresDefault "now plus 0 min"

  </ifModule>

測試:curl -x127.0.0.1:80 ‘http://www.test.com/static/image/common/logo.png‘

7.apache配置防盜鏈

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

  SetEnvIfNoCase Referer "^http://.*\.test\.com" local_ref

  SetEnvIfNoCase Referer "^http://.*\.\.com" local_ref(引用東西的網站加入白名單)

  <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png|js|css)">

    Order Allow,Deny

  Allow from env=local_ref

  </filesmatch>

8.apache存取控制

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

   #某個目錄做限制

   <Directory /data/www/>

     Order allow,deny

     Allow from all

     Deny from 127.0.0.1

   </Directory>

   #針對請求的uir去限制

   <filesmatch "(.*)admin(.*)">

      Order deny,allow

      Deny from all

      Allow from 127.0.0.1

   </filesmatch>

curl -x192.168.255.3:80 -I www.test.com

curl -x127.0.0.1:80 -I www.test.com/forum.php

9.apache禁止解析php

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

  <Directory  /data/www/data>

    php_admin_flag engine off

    <filesmatch "(.*)php">

       Order deny,allow

       Deny from all

       Allow from 127.0.0.1

    </filesmatch>

  </Directory>

curl -x127.0.0.1:80 www.test.com/data/info.php

10.apache禁止指定usr_agent

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

    # RewriteCond %{HTTP_USER_AGENT} ^.*curl.* [NC,OR]

    # RewriteCond %{HTTP_USER_AGENT} ^.*chrome*  [NC]

    # RewriteRule .* - [F]

通過rewrite限制某個目錄

      RewriteCond %{REQUEST_URI} ^.*/tmp/.* [NC]

      RewriteRule .* - [F]

apachectl restart




本文出自 “linux營運” 部落格,轉載請與作者聯絡!

apache的相關配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.