Dave
Dave

Reputation: 1718

Apache Port Proxy

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.

Upvotes: 30

Views: 64959

Answers (3)

ashen madusanka
ashen madusanka

Reputation: 742

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.

Upvotes: 1

txyoji
txyoji

Reputation: 6868

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

Upvotes: 40

BuvinJ
BuvinJ

Reputation: 11086

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

Upvotes: 8

Related Questions