You can redirect each file on a different file descriptor:
while read -r -u3 port; do
while read -r -u4 ip; do
# do stuff with $port and $ip
echo -n "$ip $port: "
OUT=$( nmap -p "$port" --script=http-headers.nse "$ip" |
tail -n 13 |
awk -F: '{print $2; exit}' )
[[ $OUT == Apache ]] && echo right || echo wrong
done 4< "$2"
done 3< "$1"