gpt4 book ai didi

nginx - 需要帮助重写子域的 Nginx 规则

转载 作者:行者123 更新时间:2023-12-01 19:46:01 26 4
gpt4 key购买 nike

不久前我做了一些重写规则,将直接访问我网站图像的人重定向到图像页面,

例如,访问 www.mysite.com/i/asdf.jpg 的人访问 www.mysite.com/pic/asdf

这是我使用的重写规则:

location /i/image_(\d+).(gif|jpg|jpeg|png)$ {
root /home/mysite/public_html;
valid_referers www.example.com mysite.com;
if ($invalid_referer) {
rewrite ^ http://www.example.com/pic/$1 permanent;
}
}

我创建了目录“i”的子域,其中包含所有图像。所以现在就像这样http://i.mysite.com/

是否可以像上面那样进行重写,这样如果文件被不同的引用者直接访问,它将达到相同的重写规则?

谢谢:)

更新:现在使用这个:

   server {
access_log off;

error_log logs/vhost-error_log warn;
listen 80;
server_name i.imgzzz.com;
root /home/imgzzz/public_html;
#location ~ ^/pic/ { alias /home/imgzzz/public_html/i; }
location ~ ^/pic/(.*)$ { alias /home/imgzzz/public_html/i/$1; }
valid_referers i.imgzzz.com www.imgzzz.com imgzzz.com;
location ~ /image_(\d+).(gif|jpg|jpeg|png)$ {
if ($invalid_referer) {
rewrite /image_(\d+).(gif|jpg|jpeg|png)$ /pic/image_$1 last;
}
}
}

Htaccess 重写:

RewriteBase /
Options +FollowSymlinks
#RewriteEngine on
rewritecond %{http_host} ^imgzzz.com [nc]
rewriterule ^(.*)$ http://www.imgzzz.com/$1 [r=301,nc]

RewriteCond %{HTTP_REFERER} !^http://(www\.)?imgzzz.com/.*$ [NC]
RewriteRule i/image_(\d+)\.(jpg|jpeg|gif) pic/$1 [L]

RewriteRule ^pic/([0-9]+)/{0,1}$ view.php?name=$1 [QSA,L]
RewriteRule ^pic/full/([0-9]+)/{0,1}$ view-f.php?name=$1 [QSA,L]
RewriteRule ^pic/([0-9]+)/feature/$ view.php?name=$1&pop=1 [QSA,L]

最佳答案

valid_referers i.imgzzz.com www.imgzzz.com imgzzz.com;location ~ /image_(\d+).(gif|jpg|jpeg|png)$ {    if ($invalid_referer) {        rewrite /image_(\d+).(gif|jpg|jpeg|png)$ /view.php?name=image_$1.$2 last;    }}

关于nginx - 需要帮助重写子域的 Nginx 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4739589/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com