LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache and mod_proxy (https://www.linuxquestions.org/questions/linux-server-73/apache-and-mod_proxy-4175444812/)

kendel 01-09-2013 07:48 AM

Apache and mod_proxy
 
I am running ubunu linux, trying to use a feature to forward a requested domain to a second server on my internal network:

webserver: 192.168.10.160 [router forwards all requests to port 80 here]
mailserver: 192.168.10.180 [has an apache client running]

I installed round cube on the mail server which works if I type http://192.168.10.180/roundcube
I then created a virtual host on the mailserver: (using webmin and on port 81)
Code:

DocumentRoot /var/www/roundcube
ServerName webmail.example.com
ServerAdmin webmaster@webmail.example.com
<Directory /var/www/roundcube>
allow from all
Options +Indexes
</Directory>

I then logged into the webserver and created the proxy:
Code:

ServerName webmail.example.com
ServerAlias webmail
ProxyPreserveHost on
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
ProxyPass / http://192.168.10.180:81/
ProxyPassReverse / http://192.168.10.180:81/
    <Location />
        Order allow,deny
        Allow from all
    </Location>

I then logged into the DNS, and created a subdomain "A" record webmail.example.com to External IP
But when you try to goto webmail.example.com it only goes to www.example.com webpage. Can anyone tell me what the possible problem is?

acid_kewpie 01-09-2013 07:54 AM

that httpd config excerpt isn't complete. Shouldn't it be within a virtualhost declaration? You'll certainly need that if you've multipkle site names on the single box. And to turn virtualhosting on in the first place.

kendel 01-09-2013 07:58 AM

The code you are referring to is
<VirtualHost *:80>
</VirtualHost>
and yes I did try that and got an error, so I went back and looked at all the domains on webmin with virtual host and none of them had the opening and closing codes, I assume webmin is already resolving them somehow (magically). The other domains on my webserver work perfectly. Trying to resolve the proxy to the mailserver has been unsuccessful.

acid_kewpie 01-09-2013 08:10 AM

well I don't use toosl like webmin, post the entire apache config as apache loads them, and it should make much more sense.

kendel 01-09-2013 08:22 AM

Wow I guess it does resolve them, but in this is the file /etc/apache2/sites-available/webmail.lampxserver.com.conf
Code:

<VirtualHost *:80>
ServerName webmail.example.com
ServerAlias webmail
ProxyPreserveHost on
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
ProxyPass / http://192.168.10.180:81/
ProxyPassReverse / http://192.168.10.180:81/
    <Location />
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>


Ramurd 01-09-2013 10:28 AM

So; You're running the VirtualHost webmail.example.com;
If people within your network go to that url, they'll resolve the machine your VH is running on.

With the ProxyPass you proxy the traffic to 192.168.10.180:81 (which is NOT an external IP :p), so: are you sure you're proxying towards the correct host?

kendel 01-09-2013 12:18 PM

I am not sure I understand what you are saying. From my understanding of proxypass it is suppose to forward traffic of a domain to the server running the services. http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
From what the example shows me, I use the proxy to forward to the internal IP serving the particular domain.

webserver is called web.example.com
mailserver is called mail.example.com

Do you mean I am suppose to use the hostname rather than the alias?

I verified that going to the internal ip apache server works, (also changed the files around to make sure the destination server works). I have a theory the problem stems from the webserver settings, but I am unable to verify

acid_kewpie 01-09-2013 02:35 PM

the vhost settings seem OK to me, and if the back end server was wrong, it wouldn't be redirecting anywhere else, you'd be getting an HTTP 503 error I think.

so on the webserver box, run this:

curl -v http://192.168.10.160 -H "Host: webmail.example.com"

and that should show you the web page from the webmail server. If not, paste the output here and we'll hopefully be able to see a little more from it. Can you confirm that named based vhosts are enabled? there should be a "NameVirtualHost *:80" directive in the main config somewhere.

kendel 01-09-2013 05:46 PM

Code:

* About to connect() to 192.168.10.160 port 80 (#0)
*  Trying 192.168.10.160... connected
> GET / HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zli                                                                                                                    b/1.2.3.4 libidn/1.23 librtmp/2.3
> Accept: */*
> Host: webmail.example.com
>
< HTTP/1.1 200 OK
< Date: Wed, 09 Jan 2013 23:43:31 GMT
< Server: Apache/2.2.22 (Ubuntu)
< Last-Modified: Tue, 08 Jan 2013 03:29:29 GMT
< ETag: "860b0d-100-4d2be8dacc0d6"
< Accept-Ranges: bytes
< Content-Length: 256
< Vary: Accept-Encoding
< Content-Type: text/html
< X-Pad: avoid browser bug
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>EXAMPLE.COM</title>
<meta http-equiv="REFRESH" content="0;url=http://www.example.com"></HEAD>
<BODY>
Please wait while we redirect you to our site.
</BODY>
</HTML>
* Connection #0 to host 192.168.10.160 left intact
* Closing connection #0


Ok it seems to be connecting to the webserver rather than the mailserver.... What would cause that? Also I didn't know how to check the vhost.

acid_kewpie 01-10-2013 02:38 AM

by checking the vhost I just meant the overall httpd config file for that line. Certainly looks clear that the virtualhost is not being used. Could the virtual name be defined twice maybe?? the *ENTIRE* config would be useful.

kendel 01-10-2013 04:19 AM

Which file the httpd.conf or apache2.conf? Amm here a 00-default.conf

acid_kewpie 01-10-2013 04:21 AM

well they can be called different things depending on the system you're running, it'd be httpd.conf or apache2.conf, but sure why you'd have both though. If in doubt, post them all.

kendel 01-11-2013 03:09 PM

I just wanted to thank you, I solved it and the solution was much simpler and well overlooked. The control panel created the domain but used a "*" wild card conf file which basically kept sending everything back to the main domain. After I fixed it to "www" it still didnt work, I had to change all the internal addresses back to port 80. So now everything works on port 80.

Original: Reverseproxy http://192.168.0.180:81/
default: Reverproxy http://192.168.0.180/

I had apache on the mail server listen to port 81, but now I defaulted it back to port 90. My last question before I sign off is, does it matter that all the apache instances among the servers are listening to port 80, will that in the future cause any possible conflicts? Or should I find out why it does not work on port 81, even though I added the Listen 81 to the conf file of apache.


All times are GMT -5. The time now is 11:48 PM.