26 lines
1.2 KiB
Bash
26 lines
1.2 KiB
Bash
#!/bin/bash
|
|
echo "--- Network namespace of openresty vs node ---"
|
|
NGINX_PID=$(ps -efL | grep "nginx" | grep -v grep | awk '{print $2}' | head -1)
|
|
NODE_PID=$(ps -efL | grep "node /opt/yuyueguahao" | grep -v grep | awk '{print $2}' | head -1)
|
|
echo "nginx: $NGINX_PID, node: $NODE_PID"
|
|
|
|
# readlink /proc/PID/ns/net
|
|
echo "nginx netns: $(readlink /proc/$NGINX_PID/ns/net)"
|
|
echo "node netns: $(readlink /proc/$NODE_PID/ns/net)"
|
|
|
|
echo "--- /etc/hosts in both contexts ---"
|
|
ls -la /proc/$NGINX_PID/root/etc/hosts 2>&1
|
|
cat /proc/$NGINX_PID/root/etc/hosts 2>&1 | head
|
|
|
|
echo "--- Test connectivity from nginx's network ns to 3000 ---"
|
|
# Run a process in nginx's netns and test
|
|
NS=$(readlink /proc/$NGINX_PID/ns/net)
|
|
echo "Testing from netns: $NS"
|
|
|
|
echo "--- Use nsenter to test ---"
|
|
nsenter -t $NGINX_PID -n -- curl -s -o /dev/null -w "HTTP %{http_code}\n" --max-time 5 http://127.0.0.1:3000/api/v1/banners
|
|
nsenter -t $NGINX_PID -n -- curl -s -o /dev/null -w "HTTP %{http_code} size=%{size_download}\n" --max-time 5 http://127.0.0.1:3000/uploads/1781403331659-1cac3cac.png
|
|
|
|
echo "--- Check if /uploads is being intercepted somewhere ---"
|
|
ls -la /proc/$NGINX_PID/root/opt/yuyueguahao/uploads 2>&1
|