Apache Port Proxy
Asked Answered
H

3

29

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.

Hanser answered 21/7, 2009 at 23:58 Comment(1)
You might have better luck with this on ServerFault.Dutton
B
39

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

Broderic answered 10/8, 2009 at 3:25 Comment(2)
If you get an internal server error: sudo a2enmod proxy sudo a2enmod proxy_http sudo service apache2 restartHetti
we shouldn't use mysite.com on stackoverflow, see meta.stackexchange.com/questions/208963/…Cardinal
B
8

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
Babu answered 5/8, 2015 at 21:44 Comment(0)
D
1

and full code would be like below.

<IfModule mod_ssl.c>
<VirtualHost *:443>
ProxyPreserveHost On
ServerAdmin webmaster@localhost
ServerName test.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass / http://localhost:9301/
ProxyPassReverse / http://localhost:9301/

SSLCertificateFile /etc/letsencrypt/live/test.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

this link also helpful.

Dosimeter answered 11/3, 2021 at 8:57 Comment(1)
Information links are great, but providing the details from the site in your answer is more accessible.Jaban

© 2022 - 2024 — McMap. All rights reserved.