大网数据广告活动
服务器运维问答

Nginx as https proxy

· 52CE 我爱测

I need to setup nginx as https proxy, but this did not work: $ export https_proxy="http://127.0.0.1:8081" $ curl https://example.com curl: (56) Received HTTP code 400 from proxy after CONNECT My nginx.conf : server { listen 8081;…

问题原文

原帖链接 · Pavel Nazarov · CC BY-SA 3.0

I need to setup nginx as https proxy, but this did not work:

$ export https_proxy="http://127.0.0.1:8081"
$ curl https://example.com
curl: (56) Received HTTP code 400 from proxy after CONNECT

My nginx.conf:

server {
    listen          8081;
    location / {
            proxy_pass              http://some.proxy.com:3128;
            proxy_set_header        Host            $http_host;
    }
}

已采纳解答

原帖链接 · kubanczyk · CC BY-SA 3.0

There is a misunderstanding here. There are two types of http proxy that are two completely different animals: a reverse proxy and a forward proxy. Don't mix them.

Forward proxy is visible for a client OS (e.g. export https_proxy) or a browser. Client side knows it needs to talk slightly differently and a forward proxy server doesn't behave like a regular webserver.

Reverse proxy is almost a normal webserver and the behavior is invisible to client side. An nginx example is proxy_pass. There are some dirty tricks to employ a reverse proxy as a forward http proxy in a limited way, but it doesn't work at all as a forward https proxy because of the CONNECT verb.

So a forward proxy would be better named a "client-side proxy". A reverse proxy would be a "server-side proxy". (Forward/reverse proxy is a horrible nomenclature in my opinion.)

Don't use nginx as a forward proxy. It's intended to be used as a regular webserver or a reverse proxy.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-04-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。