Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Need help with HTTP::Proxy

by scorpio17 (Canon)
on Dec 30, 2021 at 21:58 UTC ( #11140042=perlquestion: print w/replies, xml ) Need Help??

scorpio17 has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to create simple proxy using HTTP::Proxy as follows:
use strict; use HTTP::Proxy; my $proxy = HTTP::Proxy->new; $proxy->port( 8000 ); $proxy->init(); $proxy->agent->proxy([ [ 'http', 'https' ] => '', ]); $proxy->agent->ssl_opts( verify_hostname => 0 ); $proxy->start;
If I run this on SERVER_A, I can do the following (also on SERVER_A) and it works as expected:
curl http://localhost:8000/index
But if I'm on another host (SERVER_B, for example) and I do this:
curl http://SERVER_A:8000/index
Then I get "Failed to connect : Connection refused"
I've disabled all firewalls, for testing, but that doesn't fix it.
If I use the actual IP address (instead of hostname SERVER_A) it makes no difference.
If I run the script as root (or with sudo) it makes no difference.
What am I missing here?

For what it's worth, the reason I'm trying to do this: host SERVER_B needs to access, but isn't able to reach it directly. It can, however, reach SERVER_A, and SERVER_A can reach, so I'd like to use SERVER_A to bridge the two.

Replies are listed 'Best First'.
Re: Need help with HTTP::Proxy
by NetWallah (Canon) on Dec 30, 2021 at 22:29 UTC
    the new() method in HTTP::Proxy has the following defaults:
    my %defaults = ( agent => undef, chunk => 4096, daemon => undef, host => 'localhost', logfh => *STDERR, ...
    By default, it will only listen on 'localhost' AKA

    If you specify

    host=> your-fqdn-or-ip,
    in your call to new(), it should work the way you expect (untested).

                    "If you had better tools, you could more effectively demonstrate your total incompetence."

      Yep, that fixed it! I just added:
      below the $proxy->port(8080) line (where 111.222.333.444 is my IP).
        Opps! I spoke too fast. It's working now for HTTP, but not HTTPS.
        From the command line, curl gives me "(35) SSL Connect Error",
        and from a web browser (google chrome) I get "ERR_SSL_PROTOCOL_ERROR".
        I'm using "curl -k" thinking that would make it ignore certificate checking.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11140042]
Approved by kcott
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2022-12-05 11:19 GMT
Find Nodes?
    Voting Booth?

    No recent polls found