我有两台 Ubuntu 机器:
- A 可以访问 B,但无法访问 Internet
- B 可以访问互联网
我在机器 AI 上提供对 Internet 的访问,想要在机器 B 上设置 HTTP/HTTPS 代理,并配置 curl 和 apt-get 来使用此代理。
在 BI 上,已从 docker 镜像设置了 nginx,如下所示:
docker run -d \
--name nginx-auto-ssl \
--restart on-failure \
-p 80:80 \
-p 443:443 \
-e ALLOWED_DOMAINS=* \
-e FORCE_HTTPS=false \
valian/docker-nginx-auto-ssl
在 AI 上设置代理
export http_proxy=http://machine.b.com:80/
export https_proxy=https://machine.b.com:443/
但是,当我从 A 请求互联网资源时,我收到信息代理未配置:
curl http://www.facebook.com/ -v
* Hostname was NOT found in DNS cache
* Trying 172.25.10.202...
* Connected to machine.b.com (172.x.x.x) port 80 (#0)
> GET http://www.facebook.com/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: www.facebook.com
> Accept: */*
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 OK
* Server openresty/1.13.6.1 is not blacklisted
< Server: openresty/1.13.6.1
< Date: Tue, 29 May 2018 12:52:38 GMT
< Content-Type: text/html
< Content-Length: 562
< Last-Modified: Fri, 20 Apr 2018 14:42:38 GMT
< Connection: keep-alive
< ETag: "5ad9fc5e-232"
< Accept-Ranges: bytes
<
<!DOCTYPE html>
<html>
<head>
<title>Welcome to OpenResty!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to OpenResty!</h1>
<p>If you see this page, the OpenResty web platform is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="https://openresty.org/">openresty.org</a>.<br/></p>
<p><em>Thank you for flying OpenResty.</em></p>
</body>
</html>
答案1
与某些人声称的不同,使用 nginx 代理可以做到这一点。
这里是docker-compose.yml
:
version: '3'
services:
nginx_proxy:
container_name: "proxy"
image: reiz/nginx_proxy:latest
ports:
- 8888:8888
volumes:
- ./nginx.conf:/usr/local/nginx/conf/nginx.conf:ro
这里是nginx.conf
:
user www-data;
worker_processes auto;
daemon off; # Don't run Nginx as daemon, as we run it in Docker we need a foreground process.
events {}
http {
server_names_hash_bucket_size 128;
access_log /var/log/nginx_access.log;
error_log /var/log/nginx_errors.log;
# Whitelist Google and Heise
server {
listen 8888;
proxy_connect;
proxy_max_temp_file_size 0;
resolver 8.8.8.8;
location / {
proxy_pass http://$http_host;
proxy_set_header Host $http_host;
}
}
}