Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

Apache redirect to another port

I've struggled with this for some time and am definitely doing something wrong.

I have apache server and a JBoss server on the same machine. I'd like to redirect traffic for mydomain.com to JBoss localhost:8080/example. The DNS is currently setup for mydomain.com and it will go straight to port 80 when entered into the browser.

My question is how do I redirect to a different port when a certain domain name comes to apache (in this case, "mydomain.com")?

<VirtualHost ip.addr.is.here> 
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName mydomain.com
  ProxyPass http://mydomain.com http://localhost:8080/example
  ProxyPassReverse http://mydomain.com http://localhost:8080/example
</VirtualHost> 

UPDATED w/ Suggestions - Still not forwarding to port 8080

<VirtualHost *:80> 
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName mydomain.com
  ServerAlias www.mydomain.com
  ProxyPass http://mydomain.com http://localhost:8080/example
  ProxyPassReverse http://mydomain.com http://localhost:8080/example
</VirtualHost> 
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should leave out the domain http://example.com in ProxyPass and ProxyPassReverse and leave it as /. Additionally, you need to leave the / at the end of example/ to where it is redirecting. Also, I had some trouble with http://example.com vs. http://www.example.com - only the www worked until I made the ServerName www.example.com, and the ServerAlias example.com. Give the following a go.

<VirtualHost *:80> 
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName www.example.com
  ServerAlias example.com
  ProxyPass / http://localhost:8080/example/
  ProxyPassReverse / http://localhost:8080/example/
</VirtualHost> 

After you make these changes, add the needed modules and restart apache

sudo a2enmod proxy && sudo a2enmod proxy_http && sudo service apache2 restart

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...