У меня есть приложение django, запущенное с gunicorn на 0.0.0.0:8000 за nginx, поскольку обратный прокси-сервер прослушивает порт 1337.
version: '3.7'
services:
web:
build: .
command: gunicorn myapp.wsgi:application --name myapp --log-file - --log-level info --bind 0.0.0.0:8000
volumes:
- ./web-backend/src/:/usr/src/app/
ports:
- 8000:8000
env_file:
- .env_web
depends_on:
- db
db:
image: postgres:11.5-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- .env_db
nginx:
build: ./nginx
ports:
- 1337:80
depends_on:
- web
volumes:
postgres_data:
с nginx.conf:
upstream myapp {
server web:8000;
}
server {
listen 80;
location / {
proxy_pass http://myapp;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
Приложение, естественно, доступно с локального хоста как на 8000, так и на 1337, однако я хотел бы, чтобы оно было доступно и со всех хостов в другой сети (информация ниже).
Некоторая информация: хост приложения Django, который я могу подключиться к ssh: 10.157.100.98/24, тогда как eth0 на самом хосте - 192.168.0.13/24, который, как я полагаю, в будущем откроет порт для Интернета, но на данный момент просто чтобы у всех пользователей сети 10.157.100.0 была возможность доступа к приложению.
Tracert:
Tracing route to 10.157.100.98 over a maximum of 30 hops
1 5 ms 4 ms 5 ms 10.156.80.1
2 5 ms 4 ms 6 ms 172.30.237.241
3 3 ms 3 ms 4 ms 172.30.225.6
4 4 ms 4 ms 4 ms 172.30.225.6
5 23 ms 23 ms 23 ms 135.7.192.30
6 42 ms 42 ms 42 ms 135.7.192.7
7 42 ms 43 ms 43 ms 135.7.193.21
8 43 ms 43 ms 43 ms sth-vlan478-domain.net [172.30.8z.x1]
9 43 ms 43 ms 43 ms sth2-vlan20-domain.net [172.30.8z.x2]
10 43 ms 44 ms 44 ms sth3-vlan22-domain.net [172.30.8z.x3]
11 43 ms 45 ms 43 ms 172.30.8z.x4
12 * * * Request timed out.
13 * * * Request timed out.
14 43 ms 42 ms 45 ms 10.157.100.98
Trace complete.
маршрут
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
instance-data.e 192.168.0.1 255.255.255.255 UGH 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.30.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-df38aebf18b9
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
iptables
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:http-alt
Chain FORWARD (policy DROP)
target prot opt source destination
DOCKER-USER all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-1 all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain DOCKER (2 references)
target prot opt source destination
ACCEPT tcp -- anywhere sth5-vlan401-domain.net tcp dpt:postgresql
ACCEPT tcp -- anywhere sth6-certr01-domain.net tcp dpt:8000
ACCEPT tcp -- anywhere 172.30.0.5 tcp dpt:http
Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target prot opt source destination
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
RETURN all -- anywhere anywhere
Chain DOCKER-ISOLATION-STAGE-2 (2 references)
target prot opt source destination
DROP all -- anywhere anywhere
DROP all -- anywhere anywhere
RETURN all -- anywhere anywhere
Chain DOCKER-USER (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
route
'''
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
instance-data.e 192.168.0.1 255.255.255.255 UGH 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.30.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-df38aebf18b9
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
'''
Хочу отметить, что я полный новичок, когда дело касается сетей. Так:
Я подключаюсь через 172.30.86.42 к своему серверу приложений django, поэтому, чтобы позволить всем пользователям (которые также будут подключаться через этот прокси-сервер) для доступа к приложению через 10.157.100.98:8000 или 1337, мне нужно открыть эти порты для этого интерфейса, я прав? Есть еще что-нибудь?
Если кто-то не стесняется продемонстрировать, как трафик идет по крупицам, я считаю, что это будет полезно для всех новичков.
Решено ... У меня был Nginx для прослушивания на 1337 вместо 80, который был фактически открыт через группу безопасности в OpenStack.