Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl: Bypass proxy for localhost

Tags:

bash

curl

proxy

I'm under a proxy, and if I try curl http://localhost/mysite or curl http://127.0.0.1/mysite curl try to resolve it with the proxy. So I tried with --noproxy option, but doesn't work. Is working ok for external servers with the proxy as curl http://mysite.com.

My configuration:

  • Cygwin (bash) under Windows 8 with curl extension.
  • Proxy: proxy.domain.xx:1080 without authentication
  • http_proxy=http://proxy.domain.xx:1080
  • Local Server: XAMP Version 1.8.0
  • Apache ports: 80,443
  • Browser: Chrome with proxy, but configured to access to localhost and *.dev

From the curl --help

--noproxy : Comma-separated list of hosts which do not use proxy

What I tried:

  • I have deactivated the firewall and nothing
  • $ curl -v http://localhost/mysite -> Debug:

    Response

    Connected to proxy.domain.xx (200.55.xxx.xx) port 1080 (#0) GET http://localhost/mysite HTTP/1.1 User-Agent: curl/7.21.1 (i686-pc-mingw32) libcurl/7.21.1 OpenSSL/0.9.8r zlib/1.2.3 Host: localhost Accept: */* Proxy-Connection: Keep-Alive The system returned: <PRE><I>(111) Connection refused</I></PRE> 
  • curl -v --noproxy localhost, http://localhost/muestra

    Response

    About to connect() to localhost port 80 (#0) * Trying 127.0.0.1...  * Connected to localhost (127.0.0.1) port 80 (#0) > GET /mysite HTTP/1.1 > User-Agent: curl/7.21.1 (i686-pc-mingw32) libcurl/7.21.1 OpenSSL/0.9.8r zlib/1.2.3 > Host: localhost > Accept: */* > < HTTP/1.1 301 Moved Permanently < Server: Apache/2.4.2 (Win32) OpenSSL/1.0.1c PHP/5.4.4 < Location: http://localhost/mysite < Content-Length: 331 < Content-Type: text/html; charset=iso-8859-1 

Any idea how to fix this?

like image 297
Tom Sarduy Avatar asked Nov 26 '12 05:11

Tom Sarduy


People also ask

Does Curl use NO_PROXY?

Curl does not parse NO_PROXY environment variable same as --noproxy flag as expected #2477.

Does Curl use Http_proxy?

Another way to use proxy with curl is to set the environment variables http_proxy and https_proxy. Note that setting proxy using environment variables works only with MacOS and Linux.

Does Curl use proxy by default?

It is recommended that you enclose the proxy server address in double quotes to handle special characters in the URL correctly. Note that the default proxy protocol for Curl is HTTP.


1 Answers

After

curl -v --noproxy localhost, http://localhost/muestra 

curl responded with

About to connect() to localhost port 80 (#0) * Trying 127.0.0.1...  * Connected to localhost (127.0.0.1) port 80 (#0) 

So it clearly stated that it connected to localhost.

like image 66
Udo Klein Avatar answered Sep 18 '22 13:09

Udo Klein