Apache: subdomains, virtual host, and dynamic dns - apache

My current setup is like this. I have a registered domain name. Through my domain provider I have pointed my domain to a dynamic IP address. So mysite.com points to 97.89.120.x
I have dd-wrt router and it is keeping my dynamic IP updated and port forwarding all port 80 and 443 request to my apache server IP of 192.168.121.50 ( Nothing real crazy here)
My apache server redirects all port 80 request to port 443
cat /etc/apache2/sites-available/default
<VirtualHost *:80>
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>
cat /etc/apache2/sites-available/default-ssl
<VirtualHost _default_:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/mycloud
</VirtualHost>
This all works like a champ and is very straight forward.
I want to add a subdomain of cloud.mysite.com. So that mysite.com and cloud.mysite.com both point to the same dynamic IP 97.89.120.x From my dd-wrt router I am port forwarding all port 80 and 443 request to a new server in my environment 192.168.121.60
I want the apache server on this new host to host mysite.com and to forward request for cloud.mysite.com to the other server 192.168.121.50 and be redirected to https / ssl / ports 443.
So how exactly do I setup the virtual server to do this? I have tried similar to this without success.
NameVirtualHost *
<VirtualHost *:80>
ServerName www.mysite.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerName www.cloud.mysite.com
ServerAlias 192.168.121.50
DocumentRoot /var/www/mycloud
</VirtualHost>
How can I redirect the subdomain to a different server and get this to work?

You have a wrong understanding of virtual hosts. The purpose of vhosts is to host multiple sites on a single webserver. It is not impossible to do this with your approach, but in the case that you have several webservers and services that you want to publish to the www in one domain, you will organize this in another way.
You can do this by DNS, Gateway, Reverse Proxing, Routing and maybe other approaches.
I suggest to find an approach where the ddwrt router will organize the requests and hand them to the desired webserver.
On ddwrt, just as example for a reverse proxy and loadbalancer, you can do this with Pound: http://www.dd-wrt.com/wiki/index.php/Pound
Please let me know if you have further questions. I will edit my post then. But this is from this point a question for serverfault and not for stackoverflow.

You will need to use 192.168.121.60 as a proxy of 192.168.121.50. But this may not be the best/smart way to achieve this. Proxying a web server for another ??
You already have setup for cloud.mysite.com on 192.168.121.60. Using mod_proxy_balancer ,this will look something like below.
<VirtualHost *:80>
ServerName www.cloud.mysite.com
ServerAlias cloud.mysite.com
ProxyRequests Off
<Proxy balancer://mycluster>
BalancerMember http://192.168.121.50
</Proxy>
ProxyPass / balancer://mycluster
</VirtualHost>
The best way as pointed out by #LukasF is to have both the sites hosted on a single web server.
Hope that helps!

Related

IP and Wildcard VirtualHost Conflict

I'm trying to setup an Apache web server that has a couple WordPress Multisite installations. My goal is to have clients point their domain at one of the IP addresses say 209.50.xxx.xxx and that traffic gets directed to the WP Multisite directory. I also have other domains that need to go to a specific directory regardless of what their IP address is. I can't seem to get both IP Based and Wildcard VirtualHosts working together. I can only get one or the other. In the current setup below, I can get traffic on any domain pointed at 209.50.xxx.xxx to go to the correct directory, but app.example.com and www.example.com will just get an error "ERR_TOO_MANY_REDIRECTS".
## All Traffic to IP: 209.50.xxx.xxx on Port 80 (Catch All) ##
<VirtualHost 209.50.xxx.xxx:80>
DocumentRoot /var/www/example/site/public
</VirtualHost>
## All Traffic to IP 209.50.xxx.xxx on Port 80 with Domain app.example.com ##
<VirtualHost 209.50.xxx.xxx:80>
ServerName app.example.com
DocumentRoot /var/www/example/app/public
</VirtualHost>
## All Traffic to any IP on Port 80 with Domain www.example.com or example.com ##
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/example/main/public
</VirtualHost>
## All Traffic to any IP on Port 80 with Domain www.other-example.com or other-example.com ##
<VirtualHost *:80>
ServerName www.other-example.com
ServerAlias other-example.com
DocumentRoot /var/www/other-example/main/public
</VirtualHost>
I have tried different ordering with the current virtualhost catchall at the beginning flipped to the end with the same results.
Any ideas on how to fix this?
I setup a virtualbox with 2 IP addresses so that I could carefully test different virtual host configurations, and I believe that I have the solution. It seems that if I start using IP addresses in the VirtualHost line (<VirtualHost 192.168.1.201:80> instead of <VirtualHost *:80>) then I need to do that for every VirtualHost block. Then for the "Catch-All" blocks for each IP, I keep that first at the top of the file (The order is important.)

Using Joomla on Apache behind Apache Reverse Proxy

I have a Joomla Installation on Apache2 (Port 83) running on Ubuntu 16.04 Server.
When I connect to the page from the local network like 192.168.178.14:83 it appears and everything is fine. To access my page from the Internet there is another Server running Apache2, that acts as a Proxy Server. All traffic going trough Port 80 and 443 come to this machine, using the ServerName it decide to which machine the traffic have to be forwarded. That's working fine for about 10 domains and machines.
But when I connect to my Joomla Domain I get a HTML Site without any formatting, graphics and templates. When I forward a Port directly to this machine everything works fine again, using this port to connect.
network topologie
My VirtualHost config on Ubuntu1:
<VirtualHost *:80>
ServerName ksg-events.de
Redirect permanent / https://ksg-events.de/
</VirtualHost>
<VirtualHost *:443>
ServerName ksg-events.de
ProxyPreserveHost On
ProxyRequests Off
ProxyVia Off
ProxyPass / http://192.168.178.14:83/
ProxyPassReverse / http://192.168.178.14:83/
SSLCertificateFile /etc/letsencrypt/live/ksg-events.de/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ksg-events.de/privkey.pem
</VirtualHost>
Virtual Host config on Ubuntu2:
<VirtualHost *:83>
DocumentRoot /var/www/ksg-events.de/joomla
</VirtualHost>
Thanks for your help!
I find a solution to my problem:
Run Joomla behind Apache reverse proxy (http):
Add ProxyVia full to proxy's VirtualHost config
Using https:
Enable mod_headers on proxy server
Add RequestHeader set X-Forwarded-Proto "https" to proxy's VirtualHost
I hope that can help someone who run into the same problems.

apache redirection to niginx based on domain name

I have got APP1 running on apache httd over port 80, which will be reached via app1.abc.com , and I have got another app running on nginx over 8080 port on the same server which can be reached via app2.abc.com:8080.
Infact both app1.abc.com and app2.abc.com mapped to same IP x.x.x.1. So now I would like to know if I can configure some redirect rule in apache like, when traffic comes from app2.abc.com, with out 8080 port specified I should be internally routing this to nginx over 8080 port based on the domain that I came from.
Any help on this would be greatly helpful.
Update 1
I have tried this apache reverse proxy config.
ServerName app1.subdomain.domain.com
ServerAlias app1-app
ProxyPass / http://0.0.0.0:80/
ProxyPassReverse / http://0.0.0.0:80/
</VirtualHost>
<VirtualHost *:80>
ServerName app11.app1.subdomain.domain.com
ServerAlias vpstage-target
ProxyPass / http://0.0.0.0:8080/
ProxyPassReverse / http://0.0.0.0:8080/
</VirtualHost>

mod_proxy apache vhosts.conf

sorry for my bad English, I'm gonna try to explain my problem.... I have to do a configuration of Apache for school. I want create a web server model with three host. I have three virtual machine on virtual box and each one can communicate with an internal network. Indeed three different apache server can be seen in each vm if I call it in browser.
Now I have to configure mod_proxy.
I want this configuration: the first vm is a server, responding a specifical domain, from this server I want to reach the other 2 apache from the other 2 different vm. Server localhost ip address 192.168.1.100 vm01 localhost/vm01 link to ip address 192.168.1.101 vm02 localhost/vm02 link to ip address 192.168.1.102
So, I spend few days in apache mod_proxy but I can't find a perfect guide or example.
I try to use this vhosts.conf in server, but didn't work. Please be patient I'm new in Apache.
<VirtualHost *:8080>
ServerName localhost
DocumentRoot /home/francesco/proxy/htdocs/
</VirtualHost>
<VirtualHost *:8080>
ServerAdmin webmaster#proxy.com
ServerName www.vm01.com
ProxyPass /vm01 http://192.168.1.101
ProxyPassReverse /vm01 http://192.168.1.101
</VirtualHost>
You have defined two Virtual Hosts on port 8080. Combine it to one.
<VirtualHost *:8080>
ServerAdmin webmaster#proxy.com
ServerName www.vm01.com
ProxyPreserveHost On
ProxyPass /vm01 http://192.168.1.101
ProxyPassReverse /vm01 http://192.168.1.101
</VirtualHost>

Apache host header proxy

I have multiple urls coming into a server. I want to user host headers to redirect the traffic. I am trying to use Apache to redirect these requests to various servers that are inside our firewall. I have gotten part of the solution, but, I seem to be missing something.
For example, http://hostHeader1.mycompany.com should be redirected to a server inside our firewall that handles requests for hostHeader1, and the result should be handed back to the client. http://hostHeader2.mycompany.com should be redirected to a server inside our firewall that handles requests for hostHeader2. Etc.
Right now, I have the following, but, it redirects all traffic to http://hostHeader1Handler/:
<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass / http://hostHeader1Handler/
ProxyPassReverse / http://hostHeader1Handler/
ServerName hostHeader1.mycompany.com
</VirtualHost>
Any help appreciated.
Scott
This is probably your first or your only virtual host. Just add another virtual host before. Then this should be the new default.
NameVirtualHost *:*
<VirtualHost *:*>
ServerName your.default.domain.de
DocumentRoot /var/www/pathToHTML
</VirtualHost>
<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass / http://hostHeader1Handler/
ProxyPassReverse / http://hostHeader1Handler/
ServerName hostHeader1.mycompany.com
</VirtualHost>