일부 특정 도메인에 대해 HTTP :: Proxy를 서버 403 오류에 사용하려고합니다. 이미 헤더를 수정할 수 있었지만 프록시는 원래 페이지를 계속 제공합니다. 여기 HTTP :: Proxy : 전체 html 페이지를 대체하는 방법
내가 사용하고 코드입니다 : 여기package Filters::Filter403;
use strict;
use warnings;
use HTTP::Proxy::HeaderFilter::simple;
use HTTP::Proxy::BodyFilter::simple;
our $header = HTTP::Proxy::HeaderFilter::simple->new (
sub {
$_[2]->code(403);
$_[2]->message ('Forbidden');
}
);
our $body = HTTP::Proxy::BodyFilter::simple->new (
sub {
$_[1] = \<<'HTML';
<!DOCTYPE html>
<html><head><title>403 Forbidden</title><style type="text/css">
body { padding: 40pt; }
body, h1, h2, p { color: #333; font-family: Arial, sans-serif; margin: 0; }
div { width: 200px; background: #eee; padding: 2em; }
</style></head><body><div><h1>403</h1><h2>Forbidden</h2></div></body></html>
HTML
}
);
1;
나는이 두 개의 필터를 호출하고있어 주요 스크립트 코드입니다, 그래서 당신은 더 나은 모습 가질 수 있습니다
use HTTP::Proxy qw(:log);
use Getopt::Long;
use FindBin qw($Bin);
use lib $Bin;
use Filters;
use HTTP::Proxy::BodyFilter::complete;
my $port = 3128;
my $fail_at;
my $outputfile = '/var/log/cvmfs-test/webproxy.output';
my $errorfile = '/var/log/cvmfs-test/webproxy.error';
my $ret = GetOptions ("port=i" => \$port,
"fail=s" => \$fail_at);
my @fail_at = split(/,/, $fail_at);
# Opening file for log
open (LOG, '>>', $outputfile);
my $proxy = HTTP::Proxy->new;
$proxy->port($port);
$proxy->logfh(*LOG);
$proxy->logmask(ALL);
if ($fail_at[0] ne 'all') {
foreach my $url (@fail_at) {
$proxy->push_filter(
host => $url,
response => HTTP::Proxy::BodyFilter::complete->new,
response => $Filters::Filter403::header,
response => $Filters::Filter403::body
);
}
}
else {
$proxy->push_filter (
response => HTTP::Proxy::BodyFilter::complete->new(),
response => $Filters::Filter403::header,
response => $Filters::Filter403::body
);
}
my $pid = fork();
# Command for the forked process
if (defined($pid) and $pid == 0) {
open (my $errfh, '>', $errorfile);
STDOUT->fdopen(\*$errfh, 'w') || die "Couldn't set STDERR to $errorfile: $!\n";
$proxy->start;
}
# Command for the main script
unless ($pid == 0) {
print "Proxy HTTP started on port $port with PID $pid.\n";
print "You can read its output in $outputfile.\n";
}
exit 0;
을
도와주세요. Daxim 솔루션을 사용해 보았는데 설명서로도 보이는 것처럼 $ { $_[1] }
을 사용하려고했지만 작동하지 않았습니다.
대단히 감사합니다.
wget -S를 프록시에 확인하여 컨텐츠가 만료되는 시점을 확인할 수 있습니다. 10 년이 지난다면이 프록시 캐시에 들어야합니다. – Andrew