本文介绍了反向代理到另一台计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试执行的操作的说明:
我在IP 192.168.1.10(扩展坞反向代理)和192.168.1.20(其他服务)上有两台服务器。我希望10将请求重定向到20(这些请求中的许多都是使用SSL的)。示例:
例如_内部网 | → | 192.168.1.10 | → | https://example_internal.host.com |
Example_Extraal.Host.com | → | 192.168.1.20 | → | https://example_external.host.com |
docker-pose.yaml:
version: '3'
services:
nginx-proxy:
image: budry/jwilder-nginx-proxy-arm:0.6.0
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- certs:/etc/nginx/certs:ro
- confd:/etc/nginx/conf.d
- vhostd:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
labels:
- com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy
environment:
- DEFAULT_HOST=example_external.host.com
networks:
- frontend
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion:stable
restart: always
volumes:
- certs:/etc/nginx/certs:rw
- confd:/etc/nginx/conf.d
- vhostd:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
- [email protected]
networks:
- frontend
depends_on:
- nginx-proxy
nginx_internal:
image: nginx:stable-alpine
hostname: example_internal.host.com
restart: always
expose:
- "80"
volumes:
- /var/www/html:/usr/share/nginx/html:rw
environment:
- VIRTUAL_HOST=example_internal.host.com
- LETSENCRYPT_HOST=example_internal.host.com
- NGINX_HOST=example_internal.host.com
- [email protected]
depends_on:
- nginx-proxy
- letsencrypt
networks:
- frontend
nginx_external:
hostname: example.host.com
restart: always
build:
context: ./scm-proxy
expose:
- "80"
environment:
- VIRTUAL_HOST=example_external.host.com
- LETSENCRYPT_HOST=example_external.host.com
- [email protected]
- ENABLE_NGINX_REMOTEIP=1
depends_on:
- nginx-proxy
- letsencrypt
networks:
- frontend
networks:
frontend:
driver: bridge
SCM-Proxy/Dockerfile:
FROM nginx:1.15-alpine
COPY nginx.conf /etc/nginx/nginx.conf
SCM-Proxy/nginx.conf:
worker_processes 1;
events {
worker_connections 1024;
}
http {
sendfile on;
client_max_body_size 0;
chunked_transfer_encoding on;
server {
listen 80;
location / {
proxy_pass http://localhost:80;
proxy_redirect off;
proxy_set_header Host $http_host; # required for docker client's sake
proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
(我在一些地方读到,我必须输入";/etc/hosts";的域名解析,类似于";192.168.1.20 Example_Exteral.Host.com";)
事实是,这是我第一次使用这项技术,我还没有找到很多信息,我找到的东西很难理解。
id="this-is-the-configuration-that-has-worked-for-me">This
评论:
缺少某些详细信息,例如nginx.conf
文件自动获取server_name
字段中的example_external.host.com
,但它将在以后使用。
另一方面,您必须小心DEFAULT_HOST=
如果声明它,您可能会收到错误。我建议先对它进行注释,直到它起作用,然后再取消对它的注释
我建议使用此命令:docker-compose up -d --remove-orphans --build
文件:
docker-compose.yaml:
version: '3'
services:
nginx-proxy:
image: budry/jwilder-nginx-proxy-arm:0.6.0
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- certs:/etc/nginx/certs:ro
- confd:/etc/nginx/conf.d
- vhostd:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
labels:
- com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy
# environment:
# - DEFAULT_HOST=example_internal.host.com
networks:
- frontend
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion:stable
restart: always
volumes:
- certs:/etc/nginx/certs:rw
- confd:/etc/nginx/conf.d
- vhostd:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
- [email protected]
networks:
- frontend
nginx_external1:
container_name: tests
restart: always
build:
context: ./scm-proxy
expose:
- "80"
environment:
- VIRTUAL_HOST=example_external.host.com
- LETSENCRYPT_HOST=example_external.host.com
- [email protected]
extra_hosts:
- "example_external.host.com:192.168.1.20"
depends_on:
- nginx-proxy
- letsencrypt
networks:
- frontend
networks:
frontend:
driver: bridge
scm-proxy/Dockerfile:
FROM nginx:stable-alpine
COPY nginx.conf /etc/nginx/nginx.conf
scm-proxy/nginx.conf:
events {
worker_connections 1024;
}
http {
server {
listen 80;
listen [::]:80;
server_name example_external.host.com;
#
location / {
# proxy_pass http://example.com;
# proxy_pass http://192.168.1.20;
proxy_pass http://example_external.host.com;
}
}
}
特别感谢@richardsefton的奉献
这篇关于反向代理到另一台计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!