This can be done for HTTP and HTTPS with a "reverse proxy" that examines the host-header information in a HTTP request, gets the appropriate content and returns it.
Microsoft's ISA (Internet Security and Acceleration) can do this, so can apache/squid on Linux.
For all other ports you have a harder time, because most traffic doesn't include the desired hostname, just a target IP (eg: "I want to SSH to 1.2.3.4" instead of "I want to SSH to host1.mydomain.com)
Mapping specific external ports to internal ports is easy (port 22 -> host1:22, port 23 to host2:22, port 24 -> host3:22 etc) and is sometimes all that is needed.
If you really need to map all ports to different internal servers you will need multiple external IP addresses, which most ISPs can provide (at least if you have a business connection)
When you say "a PHP script" do you mean a PHP script on a webserver elsewhere, or a PHP script run on the command line locally?
I've done sending the mail to a website elsewhere using exim4 and curl, by creating a custom transport like so:
send_to_site:
driver = pipe
command = /usr/bin/curl https://example.com/mail.php --data-urlencode "mail@-"
user = nobody
group = nogroup
return_path_add
delivery_date_add
envelope_to_add
If you are using Debian's "split configuration" option, you would create a file in /etc/exim4/conf.d/transport/
with this in it. The command
here will pass the entire email (headers and body) to mail.php
in the variable $_REQUEST["mail"]
. You'll need to have your PHP script handle the headers.
To trigger the transport you'll need to have a router
configured that matches whatever email you want to receive and uses the above transport
to send it. With split configuration, routers go in /etc/exim4/conf.d/router/
. For capturing ALL the mail for a specific domain, I haven't tested this but I think this is right:
catchall_mail:
driver = accept
domains = mydomain.com
transport = send_to_site
Debian numbers the files in the router directory to set the order routers are checked in. The first matching router will be used to handle the email. From my configuration here, you'd probably want to number yours around 450 to go after aliases and before the routers that handle local users like hubusers
and procmail
.
After adding these files to the transport and router directories, you will need to run update-exim4.conf
to have Debian create the configuration file exim actually reads.
Best Answer
You probably need to replace
".*\\.mydomain\\.com"
with".*\.mydomain\.com"
and restartlighttpd
. If that doesn't help: please explain how the redirect isn't working for you.