如何阻止网站被恶意反向代理访问(防网站镜像)
最近有人用小站数据,利用反向代理技术,做了个小偷站。用户访问的是他的网址,但实质上内容数据确是我的,这是一起恶意反向代理事件
什么是反向代理?
先说说正向代理的概念:
正向代理,也就是传说中的代理,他的工作原理就像一个跳板。简单的说,我是一个用户,我访问不了某网站,但是我能访问一个代理服务器。这个代理服务器呢,他能访问那个我不能访问的网站,于是我先连上代理服务器,告诉他我需要那个无法访问网站的内容,代理服务器去取回来,然后返回给我。从网站的角度,只在代理服务器来取内容的时候有一次记录,,有时候并不知道是用户的请求,也隐藏了用户的资料,这取决于代理告不告诉网站。
结论就是,正向代理是一个位于客户端和原始服务器(origin server)之间的服务器,为了从原始服务器取得内容,客户端向代理发送一个请求并指定目标(原始服务器),然后代理向原始服务器转交请求并将获得的内容返回给客户端。客户端必须要进行一些特别的设置才能使用正向代理。
那么反向代理的概念呢?
比如用户访问 这个页面,但实际上并不存在这个页面,他是偷偷从另外一台服务器上取回来,然后作为自己的内容吐给用户。
但用户并不知情,这很正常,用户一般都很笨。这里所提到的 这个域名对应的服务器就设置了反向代理功能。
结论就是反向代理正好相反,对于客户端而言它就像是原始服务器,并且客户端不需要进行任何特别的设置。客户端向反向代理 的命名空间(name-space)中的内容发送普通请求,接着反向代理将判断向何处(原始服务器)转交请求,并将获得的内容返回给客户端,就像这些内容原本就是它自己的一样。
恶意反向代理的危害
网站被恶意反向代理有什么危害呢?这里列举一下:
•首先肯定会占用服务器资源,网站打开速度受影响。
•其次,别人通过代理盗用你的网站数据,对用户与不是那么智能的搜索引擎而言,相当于建了一个与你一模一样的站点,那么很有可能你的站点会进搜索引擎沙箱,甚至被降权。
•如果被恶意代理的页面,还挂有你的联盟广告(比如Adsense),这就十分危险了,如果有人点击了上面的广告,很容易被Adsense封号。
•还有很多危害,读者可以自行脑补……
js 级别的解决方案
复制代码 代码如下:
脚本很简单,如果地址栏中的网址不是 nowamagic.net 和 中的任何一个,那么就把地址栏转向 。这段代码同样可以避免被人使用反向代理技术“伪造”一个跟自己一模一样的网站。
题外话:如何防止网站被iframe嵌入。有些人用iframe做了个框架,把我们网站嵌入其中,访客来浏览的时候,好像是在浏览他自己的网站一样,那么如何解决呢?以下方法可破:
复制代码 代码如下:
php 级别的解决方案
js 级别的解决方案虽然能够让恶意代理页面跳回来,但是对搜索引擎不怎么友好。下面是服务器端(PHP)的解决方案,代码比较简单,就不多说了。
复制代码 代码如下:
$proxy_rs = $this -> proxy_filter();
if( $proxy_rs != 'nowamagic.net' || $proxy_rs != 'www.nowamagic.net' )
{
echo '非法反向代理访问';
//header('Location: ');
exit;
}
public function proxy_filter()
{
/*
$svrUrl = 'http://' . $_SERVER['SERVER_NAME'].$_SERVER["PHP_SELF"];
if (!empty($_SERVER["QUERY_STRING"]))
{
$svrUrl .= "?".$_SERVER["QUERY_STRING"];
}
return $svrUrl;
*/
return $_SERVER['SERVER_NAME'];
}
htaccess 级别的解决方案
.htaccess
复制代码 代码如下:
RewriteEngine On
RewriteBase /
php_value auto_append_file proxy.php
proxy.php
复制代码 代码如下:
$f = getenv("HTTP_X_FORWARDED_FOR");
$server = getenv("HTTP_HOST");
if (($f!="")&&($server!="nowamagic.net")&&($server!="www.nowamagic.net")){
echo '本服务器禁止恶意反向代理!';
}
?>
这个由于我网站的特殊性,没试验过,但是网上常用这种方法。
Apache httpd.conf 级别的解决方案
这个 Apache 上如何禁止我还没捣鼓出来, Nginx 倒可以,但是我用的是 Apache,如果你知道,请告诉我下~

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use Nginx with FastAPI for reverse proxy and load balancing Introduction: FastAPI and Nginx are two very popular web development tools. FastAPI is a high-performance Python framework, and Nginx is a powerful reverse proxy server. Using these two tools together can improve the performance and reliability of your web applications. In this article, we will learn how to use Nginx with FastAPI for reverse proxy and load balancing. What is reverse generation

Nginx is a high-performance, open source, and versatile web server that is also widely used as a reverse proxy server. Reverse proxy servers can be used to provide features such as load balancing, high availability, access control, and traffic control. This article will introduce the application of access control and flow control in Nginx reverse proxy. 1. Access control IP address blacklist/whitelist Nginx can implement access control on requests by configuring IP address blacklist or whitelist. IP addresses in the blacklist will be denied access, while IP addresses in the whitelist

With the rapid development of web applications, more and more enterprises tend to use Golang language for development. In Golang development, using the Gin framework is a very popular choice. The Gin framework is a high-performance web framework that uses fasthttp as the HTTP engine and has a lightweight and elegant API design. In this article, we will delve into the application of reverse proxy and request forwarding in the Gin framework. The concept of reverse proxy The concept of reverse proxy is to use the proxy server to make the client

How to use NginxProxyManager to implement reverse proxy under HTTPS protocol. In recent years, with the popularity of the Internet and the diversification of application scenarios, the access methods of websites and applications have become more and more complex. In order to improve website access efficiency and security, many websites have begun to use reverse proxies to handle user requests. The reverse proxy for the HTTPS protocol plays an important role in protecting user privacy and ensuring communication security. This article will introduce how to use NginxProxy

Nginx reverse proxy cache configuration to improve website access speed Introduction: In the Internet era, website access speed is crucial. A website that loads slowly makes users impatient and can lead to user churn. In order to improve the access speed of the website, a common way is to reduce the load on the server and speed up the loading of the page by using reverse proxy cache. This article will introduce how to use Nginx to configure reverse proxy cache to improve website access speed. 1. What is Nginx reverse proxy cache? Ngin

Nginx reverse proxy cache configuration to achieve static web page access acceleration Introduction: With the rapid development of the Internet, access speed has become a very important factor in website operations. In order to improve the access speed of web pages, we can use Nginx reverse proxy caching technology to accelerate web pages. This article will introduce how to use Nginx to configure reverse proxy cache to accelerate static web pages. Nginx reverse proxy cache configuration: Install Nginx: First you need to install the Nginx server, which can be done through apt-ge

How to implement the reverse proxy function in the Workerman document requires specific code examples. Introduction: Workerman is a high-performance PHP multi-process network communication framework that provides rich functions and powerful performance and is widely used in Web real-time communication and long connections. Service scenarios. Among them, Workerman also supports the reverse proxy function, which can realize load balancing and static resource caching when the server provides external services. This article will introduce how to use Workerman to implement the reverse proxy function.

Nginx is a high-performance web server and reverse proxy server. Its powerful configuration capabilities enable Nginx to be used in a variety of different scenarios. Among them, ACL configuration based on HTTP verbs and paths is a commonly used method in Nginx reverse proxy. This article will introduce its principle and implementation method. 1. The concept of ACL ACL (AccessControlList) is an access control list, which is a rule-based access control technology. By defining some rules, different access
