问题
I have a non-Apache server listening to port 8001 and Apache listening port 80. I want a certain virtual domain to actually be served by the non-Apache server over port 80.
Example:
<VirtualHost *:80>
Servername example.com
# Forward this on to the server on port 8001
</VirtualHost>
I thought I could do this with mod_proxy and ProxyPass with something like this.
ProxyPass * http://www.example.com:8001/
But that doesn't work.
回答1:
ProxyPass * http://www.example.com:8001/
star is only valid in a block. Forward slash is what you want.
ProxyPass / http://www.example.com:8001/
ProxyPassReverse / http://www.example.com:8001/
The reverse proxy ensures that redirects sent by your port 8001 server are adjusted to the canonical name name of your proxy.
The apache manual has some examples. http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
回答2:
I have a site hosted by apache on port 80. I also have a python web server listening on port 8880, which needed accessed via http://[mydomainname]/something. Using txyoji's answer, I got it working by simply adding a proxy pass to my virtual host definition like so:
ProxyPass /something http://mydomainname:8880/something
ProxyPassReverse /something http://mydomainname:8880/something
UPDATE
Depending your setup, an even better way to do this is to setup a proxy pass for a port on "localhost". I think it's a bit more clear what you're doing, plus more portable. Along with this, you don't have to even open up the firewall to that port! You can proxy pass locally to any port, so there is no reason to expose that to the outside world if you don't have to. Funnel everything through port 80 and have Apache always "run out in front". Then, you can just worry about the security of that.
ProxyPass /something http://localhost:8880/something
ProxyPassReverse /something http://localhost:8880/something
来源:https://stackoverflow.com/questions/1162375/apache-port-proxy