I'm not at all experienced when using proxies but hopefully this is possible.
I have apache running on my development machine which hosts a website (www.testdomain.com). I need to look at www.testdomain.com from my phone. I don't want to root my phone so all I can do is enter the IP address of my machine (10.8.0.1). The site hosted at www.testdomain.com won't work correctly as the default site in apache.
I need some way of passing through a request to 10.8.0.1 to www.testdomain.com without my phone having to look up the DNS record for www.testdomanin.com
Is this possible using mod_proxy? Is there something else that will do the job?
First of all, I don't really understand why can't you point your cellphone browser to www.testdomain.com.
Anyway, you could use a proxy, but I think a better approach would be to use a ServerAlias directive in your www.testdomain.com vhost:
<VirtualHost *:80>
ServerName www.testdomain.com
ServerAlias 10.8.0.1
(...)
If you still want to use a proxy, you could setup a different vhost for 10.8.0.1:
<VirtualHost *:80>
ServerName 10.8.0.1
ErrorLog ...
TransferLog ...
LogLevel warn
# ReverseProxy
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://www.testdomain.com/
ProxyPassReverse / http://www.testdomain.com/
(...)
ref: http://httpd.apache.org/docs/current/vhosts/name-based.html
Related
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>
I have a unix system whose actual name is "ech-10.45.25.12"
i have installed apache server in it.
Now i need to configure it in such a way that the two applications running in the same machine in tomcat in two different ports should be accessed by the same domain.
ie., i have two applications running in the same machine under different port
http://ech-10.45.25.12:8080/issuetracker/
http://ech-10.45.25.12:8180/dashboard/
I would like to name this server(ech-10.45.25.12) as devjunior.mycompany.com
The following is the configuration i have made in httpd.conf
Listen 80
Listen 8080
Listen 8180
NameVirtualHost ech-10.45.25.12:80
NameVirtualHost ech-10.45.25.12:8080
NameVirtualHost ech-10.45.25.12:8180
<VirtualHost ech-10.45.25.12:80>
ServerName devjunior.mycompany.com
DocumentRoot /www/domain-80
</VirtualHost>
<VirtualHost ech-10.45.25.12:8080>
ServerName devjunior.mycompany.com
DocumentRoot /www/domain-8080
</VirtualHost>
<VirtualHost ech-10.45.25.12:8180>
ServerName devjunior.mycompany.com
DocumentRoot /www/domain-8080
</VirtualHost>
i know i am doing a major mistake
But i should be able to access the applications by using the following urls
http://devjunior.mycompany.com/issuetracker
http://devjunior.mycompany.com/dashboard
Should i create ANY directories under any folders any where in the system
Please tell that also.
You configured only the names. So you've configured Apache to listen for:
http://devjunior.mycompany.com:8080
http://devjunior.mycompany.com:8180
You can:
Configure 2 domains with namevirtualhost without using ports. this is the most elegant way of doing what you want
Configure a single domain that points to a single directory on the filesystem with 2 links for the diferrent applications. This works with php mostly or pure html pages. With more complex applications you could incur in a lot of headache..
Domain and port. Like you've done. But you can access only by http://devjunior.mycompany.com:8080/issuetracker and http://devjunior.mycompany.com:8180/dashboard
Solution 1
You can use different domains or subdomains (which are cookie friendly in an eventuality of single sign on).
Listen 80
NameVirtualHost ech-10.45.25.12:80
<VirtualHost ech-10.45.25.12:80>
ServerName devjunior.mycompany.com
DocumentRoot /www/domain-80
</VirtualHost>
<VirtualHost ech-10.45.25.12:80>
ServerName dashboard.devjunior.mycompany.com
DocumentRoot /www/domain-8080
</VirtualHost>
<VirtualHost ech-10.45.25.12:80>
ServerName issuetracker.devjunior.mycompany.com
DocumentRoot /www/domain-8180
</VirtualHost>
Solution 2 is left as an excercise for the reader... :P
Here is what i did to make it work.
Though the change of name in etc/hosts file did nothing in my intranet, so i used the actual name of the machine which is ech-10.45.25.12
NameVirtualHost ech-10.45.25.12:80
<VirtualHost ech-10.45.25.12:80>
ServerName ech-10.45.25.12
ProxyPreserveHost on
ProxyPass /issuetracker http://ech-10.45.25.12:8080/issuetracker
ProxyPass /dashboard http://ech-10.45.25.12:8180/dashboard
</VirtualHost>
Also dont forget to add the "proxyName" & "proxyPort" attribute to the tag in tomcat's server.xml
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>
I'm having trouble with making a subdomain to my Windows computer while using AJP to proxy to Tomcat. This is what I have in my httpd.conf file:
<VirtualHost *:80>
ServerName subdomain.localhost
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:8009/folder/
ProxyPassReverse / ajp://localhost:8009/folder/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>
The subdomain has been added to `c:\windows\system32\drivers\etc\hosts
127.0.0.1 localhost
127.0.0.1 subdomain.localhost
When I go to http://localhost i goes straight to the proxy. When I go to http://subdomain.localhost i goes to the proxy as well. How do I make is so the subdomain only goes to the proxy and the regular goes to Apache?
You need to declare a second VirtualHost with localhost as the ServerName.
This should probably be moved to superuser.com but one thing to try:
<VirtualHost *:80> informs it to accept all incoming connections on port 80 to use these settings. I would try changing it to say:
<VirtualHost subdomain.localhost:80>
and see if that only applies these settings when the subdomain is used.
The ServerName tag that you put with the subdomain doesn't tell it who to listen for. The official documentation states:
The ServerName directive sets the
hostname and port that the server uses
to identify itself. This is used when
creating redirection URLs. For
example, if the name of the machine
hosting the web server is
simple.example.com, but the machine
also has the DNS alias www.example.com
and you wish the web server to be so
identified, the following directive
should be used:
You can read more on these configurations here.
I have two applications, one is the www.myexample.com, another is the blog.myexample.com. I am using PHP and Apache.
Now, I want to let www.myexample.com runs on port 82 of my machine, and blog.myexample.com on port 83, on the same machine. How to configure the apache and/ or the PHP scripts so that when the requests for the requests are served properly?
Edit: Thanks for everyone who responds, but I afraid I don't get the question clear-- my bad!
What I really want is to simulate a condition whereby the www.myexample.com and blog.myexample.com are located on different machines. So when a request comes in, the gateway server ( the one which is also hosting www.myexample.com) will check whether this is a request for www.myexample.com or for blog.myexample.com and does the necessary reroutes.
How to do this? Thanks.
I will assume that you have your own reason for wanting the two sites (www and blog) to run on different ports - and in different processes. If this is not what you intended, e.g. you did not want to have two distinct processes, then having different ports may not be what you intended either: use VirtualHost instead, to co-host the two domains within the same apache+php instance on port 80. Otherwise, read on.
Assuming that you have your two apache+php processes listening on localhost:82 and localhost:83 respectively, bring up a third, apache-only process to act as a reverse proxy. Have the reverse proxy apache instance listen for requests coming on port 80 from the internet, with two virtual host definitions. The first virtual host definition, www, would forward requests to localhost:82, whereas the second virtual host definition, blog, would forward requests to locahost:83, e.g.:
NameVirtualHost *:80
# www
<VirtualHost *:80>
ServerName www.myexample.com
ProxyPass / http://localhost:82/
ProxyPassReverse / http://localhost:82/
</VirtualHost>
# blog
<VirtualHost *:80>
ServerName blog.myexample.com
ProxyPass / http://localhost:83/
ProxyPassReverse / http://localhost:83/
</VirtualHost>
I use proxy for this type of things.
In my example, I have apache 1.3 running on port 80, but I needed svn repository to run on apache 2.2, and I didn't want to type :82 on the end of the domain every time. So I made proxy redirection on apache 1.3 (port 80):
<VirtualHost *:80>
ServerName svn.mydomain.com
ServerAlias svn
ServerAdmin my#email.com
<IfModule mod_proxy.c>
ProxyPass / http://svn:82/
</IfModule>
</VirtualHost>
Run the following line on terminal (specify your domain and sub domain name correctly)
sudo nano /etc/apache2/sites-available/subdomain.domain.com.conf
Paste the following code and change as your requirement
<VirtualHost *:80>
ServerAdmin admin#domain.com
ServerName subdomain.domain.com
ServerAlias subdomain.domain.com
ProxyRequests Off
#ProxyPass / http://localhost:8080/
<Location />
ProxyPreserveHost On
ProxyPass http://domain.com:8080/
ProxyPassReverse http://domain.com:8080/
</Location>
# Uncomment the line below if your site uses SSL.
#SSLProxyEngine On
</VirtualHost>
Run the following lines on terminal (specify your domain and sub domain name correctly)
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod subdomain.domain.com.conf
sudo service apache2 restart
Off the top of my hat:
Listen 82
Listen 83
NameVirtualHost 1.2.3.4 # Use your server's IP here
<VirtualHost www.myexample.com:82>
# Configure www.myexample.com here
</VirtualHost>
<VirtualHost blog.myexample.com:83>
# Configure blog.myexample.com here
</VirtualHost>
A more complete answer to this would be to do something like this which allow you to setup a proxy gateway which is what is loosly described above.
ServerName localhost
<Proxy *>
Order deny,allow
Allow from localhost
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:10081/
ProxyPassReverse / http://localhost:10081/
ProxyPassReverseCookiePath / http://localhost:10081/