189 8069 5689

Apache的配置-创新互联

Apache默认虚拟主机

尧都网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站开发等网站项目制作,到程序开发,运营维护。创新互联自2013年起到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联。

在虚拟主机配置文件中第一个虚拟主机

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

#   ServerAdmin webmaster@dummy-host.example.com

DocumentRoot "/tmp/123"

ServerName 111.com

保存后

mkdir /tmp/123

chmod 600 /tmp/123

Apache域名301跳转

在虚拟主机配置文件中加入

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

#    RewriteEngine on

RewriteCond %{HTTP_HOST} ^bbb.com

RewriteRule ^/(.*)$ https://cache.yisu.com/upload/information/20200310/68/125221.jpg$" p_w_picpath-request

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

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

SetEnvIf Request_URI ".*\.bmp$" p_w_picpath-request

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

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

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

CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com__%Y%m%d_log 86400" combined env=!p_w_picpath-request

2.2 Apache 配置静态缓存

修改虚拟主机配置文件

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

ErrorLog "/usr/local/apache2/logs/tset.com-error_log"

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

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

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

SetEnvIf Request_URI ".*\.bmp$" p_w_picpath-request

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

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

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

CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com__%Y%m%d_log 86400" combined env=!p_w_picpath-request

ExpiresActive on

ExpiresByType p_w_picpath/gif "access plus 1 days"

ExpiresByType p_w_picpath/jpeg "access plus 24 hours"

ExpiresByType p_w_picpath/png "access plus 24 hours"

ExpiresByType txt/ccs "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"

2.3 Apache配置防盗链

修改虚拟主机配置文件加上

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

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

SetEnvIfNoCase Referer ".*\.bbb\.com" local_ref

SetEnvIfNoCase Referer "^$" local_ref

Order Allow,Deny

Allow from env=local_ref

Apache访问控制

在虚拟主机配置文件加上

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

AllowOverride None

Order allow,deny

Allow from all

Deny from 1.1.1.1

Apache禁止解析php

在虚拟主机配置文件加上

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

php_admin_flag engine off

Order deny,allow

Deny from all

Apache 禁止指定user_agent

user_agent 搜索引擎

限制了curl 和chrome 浏览器访问

RewriteEngine on          相当于开关

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

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

RewriteRule .* - [F]

Apache通过rewrite限制某个目录

RewriteEngine on          相当于开关

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

RewriteRule .* - [F]

Apache--admin加密

在虚拟主机配置文件加上

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

AllowOverride AuthConfig

AuthName "aaaaa"

AuthType Basic

AuthUserFile /data/.htpasswd

require valid-user

保存后创建Apache的验证用户

/usr/local/apache2/bin/htpasswd -c /data/.htpasswd user

-----------------------------------------------------------------

总配置文件

#   ServerAdmin webmaster@dummy-host.example.com

DocumentRoot "/tmp/123"

ServerName 111.com

#   ServerAdmin webmaster@dummy-host.example.com

DocumentRoot "/data/www/"

ServerName aaa.com

ServerAlias bbb.com

#   ErrorLog "logs/test2.com-error_log"

#   CustomLog "logs/test2.com_log" combined

ErrorLog "/usr/local/apache2/logs/tset.com-error_log"

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

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

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

SetEnvIf Request_URI ".*\.bmp$" p_w_picpath-request

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

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

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

CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com__%Y%m%d_log 86400" combined env=!p_w_picpath-request

ExpiresActive on

ExpiresByType p_w_picpath/gif "access plus 1 days"

ExpiresByType p_w_picpath/jpeg "access plus 24 hours"

ExpiresByType p_w_picpath/png "access plus 24 hours"

ExpiresByType txt/ccs "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"

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

SetEnvIfNoCase Referer ".*\.bbb\.com" local_ref

SetEnvIfNoCase Referer "^$" local_ref

Order Allow,Deny

Allow from env=local_ref

RewriteEngine on

RewriteCond %{HTTP_HOST} ^bbb.com

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

RewriteEngine on

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

RewriteRule .* - [F]

AllowOverride AuthConfig

AuthName "aaaaa"

AuthType Basic

AuthUserFile /data/.htpasswd

require valid-user

AllowOverride None

Order allow,deny

Allow from all

Deny from 1.1.1.1

php_admin_flag engine off

Order deny,allow

Deny from all

AllowOverride AuthConfig

AuthName "aaaaa"

AuthType Basic

AuthUserFile /data/.htpasswd

require valid-user

RewriteEngine on

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

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

RewriteRule .* - [F]

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文名称:Apache的配置-创新互联
网页网址:http://cdxtjz.cn/article/deecih.html

其他资讯