# How to forbidden other site stealing my forum attachment?

**URL:** <https://www.ruby-forum.com/t/how-to-forbidden-other-site-stealing-my-forum-attachment/244816>\
**Category:** NGINX\
**Created:** [June 20, 2016, 7:20am UTC](https://www.ruby-forum.com/t/how-to-forbidden-other-site-stealing-my-forum-attachment/244816 "2016-06-20T07:20:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [June 20, 2016, 7:20am UTC](https://www.ruby-forum.com/t/how-to-forbidden-other-site-stealing-my-forum-attachment/244816/1 "2016-06-20T07:20:23Z")

</div>

Hello everyone,

My forum posts and attachments have been stolen much more by other site.  
and I write a nginx rule to prevent, without success, please guide.

example this forum:  
[http://dysmyh.com/thread-41217-1-1.html](http://dysmyh.com/thread-41217-1-1.html)

and my attachments url as  
[http://www.cnprint.org/bbs/attachment.php?attachmentid=205810&d=1359965752](http://www.cnprint.org/bbs/attachment.php?attachmentid=205810&d=1359965752)

and my forum domain is [www.cnprint.org](http://www.cnprint.org), and forum script put into /bbs/  
directory.

now I forbidden others site show my attachment, this rule don’t work,  
please help me.

I think should this line “location ~\* ^/bbs/attachment+.php?$” has  
mistake, but I can’t resolve it.

location ~\* ^/bbs/attachment+.php?$  
{  
valid\_referers none blocked \*.cnprint.org server\_names ~.google.  
~.baidu. ~.360. ~.bing.;  
if ($invalid\_referer) {

# return 403;

rewrite ^.\*$ [http://www.cnprint.org](http://www.cnprint.org);  
}  
}

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 20, 2016, 7:31am UTC](https://www.ruby-forum.com/t/how-to-forbidden-other-site-stealing-my-forum-attachment/244816/2 "2016-06-20T07:31:29Z")

</div>

Hi,

On Mon, Jun 20, 2016, at 14:20, 二戒 wrote:

> }  
> }

1. There’s probably another regexp location block matching the url  
before this block is defined (something like `location ~ \.php$ { }`)  
and definition order matters in regexp location.

2. You need fastcgi stuff in the block as well otherwise it’ll just  
return the attachment.php file.

3. The regexp, while does match /bbs/attachment.php fine, it is a bit  
confusing since it also matches /bbs/attachmentttttttt.ph .

3.1. might as well use exact match (`location = /bbs/attachment.php { }`).

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 20, 2016, 7:54am UTC](https://www.ruby-forum.com/t/how-to-forbidden-other-site-stealing-my-forum-attachment/244816/3 "2016-06-20T07:54:52Z")

</div>

sorry. I have found my forum can’t show attachment now.

blow is the nginx vhost config fles, where is the mistake?

thank you.

server  
{  
listen 80;  
server\_name [www.cnprint.org](http://www.cnprint.org);  
index index.php index.html index.htm;  
root /home/website/cnprint;  
location /bbs/ {  
rewrite ^/bbs/((urllist|sitemap\_).\*.(xml|txt)(.gz)?)$  
/bbs/vbseo\_sitemap/vbseo\_getsitemap.php?sitemap=$1 last;  
try\_files $uri $uri/ /bbs/vbseo.php?$args;  
}

location ~ ^/bbs/.+.php$ {  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_param SCRIPT\_FILENAME $document\_root/bbs/vbseo.php;  
include fastcgi\_params;  
}

location = /bbs/attachment.php  
{  
valid\_referers none blocked \*.cnprint.org server\_names ~.google.  
~.baidu. ~.360. ~.bing.;  
if ($invalid\_referer) {

# return 403;

rewrite ^.\*$ [http://www.cnprint.org](http://www.cnprint.org);  
}  
}

location ~ .\*.php?$  
{  
try\_files $uri =404;  
include fastcgi.conf;  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
}

location ~ .\*.(gif|jpg|jpeg|png|bmp|swf)$  
{  
expires 30d;  
}

}

2016-06-20 13:45 GMT+08:00 二戒 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 20, 2016, 7:56am UTC](https://www.ruby-forum.com/t/how-to-forbidden-other-site-stealing-my-forum-attachment/244816/4 "2016-06-20T07:56:02Z")

</div>

Hi,

On Mon, Jun 20, 2016, at 14:54, 二戒 wrote:

> index index.php index.html index.htm;  
> include fastcgi\_params;  
> }  
> If you read my message:

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 20, 2016, 7:46am UTC](https://www.ruby-forum.com/t/how-to-forbidden-other-site-stealing-my-forum-attachment/244816/5 "2016-06-20T07:46:06Z")

</div>

Edho A. ,

_thank you very much._  
_it’s work fine now._  
_have a good day, thank again._

2016-06-20 13:30 GMT+08:00 Edho A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 20, 2016, 8:10am UTC](https://www.ruby-forum.com/t/how-to-forbidden-other-site-stealing-my-forum-attachment/244816/6 "2016-06-20T08:10:38Z")

</div>

Hello,Edho A.  
sorry, just be not careful to understand.  
It’s ok now, thank again.

2016-06-20 13:55 GMT+08:00 Edho A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
