Windows 7 | Apache Reverse Proxy configuration - apache

I'm having problems with setting up a very basic ReverseProxy in Windows 7 and Apache 2.2
I have a virtual machine registered to a private IP address that I'm wanting to reverse proxy to from the host environment.
Note that for the current iteration of trying to work through this, I'm trying to reverseproxy from foo.bar.baz:* to foo.bar.com:6284
The relevant host entry is foo.bar.com
(assume that bar.com is the corporate domain)
Added
127.0.0.1 baz.bar.com
192.168.59.103 foo.bar.com
127.0.0.1 foo
Inside my Apache httpd.conf file (only including the delta for this change...deltas seem to escape some people, so I thought I'd call that out directly.),
LoadModule proxy_module modules/mod_proxy.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule rewrite_module modules/mod_rewrite.so
<VirtualHost *>
ServerName foo.bar.baz
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://foo.bar.com:6284
ProxyPassReverse / http://foo.bar.com:6284
</VirtualHost>
If I attempt to browse directly to foo.bar.com:6284, I get the expected results. Hosts resolves the name to the private IP and I see the markup that I expect. But when I attempt to browse to foo.bar.baz, I get "No Response from DNS Server."
Can anyone see what's wrong with my supposed-to-be-stupid-simple reverseproxy?

Ok, so assuming that my corporate domain name is bar.com, everything seems to route fine as long as all host entries that reference "bar" always followed it with ".com"
If I tried to enter foo.bar.net or foo.bar.org or foo.bar.floop as my host, I get "No Response from DNS Server" errors. If I enter foo.bar.com the host resolves.
While I received these errors as "Vital Security Proxy Errors", a developer on my team that is helping me test this received Trustwave errors instead.
This seems to be something specific to our network security policies.

Related

Xampp + IIS working together on the same server

I have one server with 2 ip addresses.
I have multiples applications in .net (webapi, a console application, etc) and one specific using PHP which is running on apache (w/ xampp).
I configured IIS to run on default port 80 and xampp is using port 8080.
As I said before, I have two ip addresses and two domains (eg: domain1.com and domain2.com).
I need to pinpoint domain1.com.br to the IIS app (which is working) but my php app never get reached since all the requests are directed to port 80 (which iis takes control).
What can I do to solve this?
I know that I can point both ip's to port 80 but how to tell IIS whenever he gets a request from a specific domain/host (in this case, domain2.com.br) he redirects to the port 8080?
You may need to let the apache takes the control,due to apache's redirect features.The main idea is to setup the apache, use apache's redirect features(vhost,if you prefer to call it so) to direct the special requests to your IIS server.
Change your IIS listening to port 8080 (and set the domain to your domain,domain1.com for example).Leave your apache to listen on 80.
Enable the module below in your apache config file(http.conf):
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
And Enable:
Include conf/extra/httpd-vhosts.conf
3. The next step is to setup the virtual host. Edit the config fileconf\ extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "x:\The\Dir\to\Your\Php\Site"
ServerName domain2.com.br
ErrorLog "logs/domain2-error.log"
CustomLog "logs/domain2-access.log" common
</VirtualHost>
And the setup to your domain2.com.br is Done.Restart your apache server,visit your site by domain name ,and your php site shall be working.
If the steps upon is working as expected,this shall be the last step.
<VirtualHost *:80>
ServerName your.net.site.domain.com
ProxyPreserveHost On
ProxyPass "/" "http://127.0.0.1:8080/"
ProxyPassReverse "/" "http://127.0.0.1:8080/"
ErrorLog "logs/domain1-error.log"
CustomLog "logs/domain1-access.log" common
</VirtualHost>
And now it should work as you expect it to.
Use
Reverse Proxy method
What is Reverse Proxy Method
A reverse proxy server is a type of proxy server that typically sits
behind the firewall in a private network and directs client requests
to the appropriate backend server. A reverse proxy provides an
additional level of abstraction and control to ensure the smooth flow
of network traffic between clients and servers.
Refer NGINX Documentation to know more about Reverse Proxy.
You can use reverse proxy either on your IIS or Apache(Xampp) Server. But since you have a Windows Server I recommend you to do reverse proxy on IIS server.
Example: Rewrite or Reverse proxy in IIS

How to redirect Apache 2.2 on Windows to Tomcat (same machine)

I have spent quite some time trying to figure out something apparentaly pretty trivial, but my lack of knowledge in Apache/Tomcat isn't making this easy for me.
I was asked to redirect a request coming on port 80 (Apache) to port 8080 (Tomcat.. and when that will work, to an app).
Before I changed anything, localhost:80 would show "It works" and locahost:8080 the Apache welcome page.
I did the following changes :
uncommented LoadModule proxy_module modules/mod_proxy.so & LoadModule proxy_http_module modules/mod_proxy_http.so from the httpd.conf file
uncommented Include conf/extra/httpd-vhosts.conf, always in httpd.conf
In httpd-vhosts.conf, I added :
<VirtualHost *:80>
ServerName localhost
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:8080
ProxyPassReverse / http://localhost:8080
</VirtualHost>
But when I try http://localhost, I do arrive on Apache welcome page, but all css styling, images, are missing :
I have an idea why it is not working : when I inspect my page, and look at the header i see that the link to the favicon for example is http://mydomain/myApp/images/favicon.ico, but if I copy paste that link, I will of course not find the favicon because it is not on Apache, but Tomcat (if that makes any sense). If I add the port to the URL, then it works : http://mydomain:8080/myApp/images/favicon.ico
Has this anything to do with the problem stated here : https://serverfault.com/questions/561892/how-to-handle-relative-urls-correctly-with-a-reverse-proxy ?
This is because the tomcat response headers will contain the proxy headers (i.e. the Location header is http://localhost/WebApp rather than http://localhost:8080/WebApp) because ProxyPreserveHost is switched On
So I switched it to Off :
<VirtualHost *:80>
ServerName localhost
ProxyRequests Off
ProxyPreserveHost Off
ProxyPass / http://localhost:8080
ProxyPassReverse / http://localhost:8080
</VirtualHost>
But the page still will not show correctly.
Thank you for your input.
Just figured this one out myself. Solution is to add a / to the end of the addresses in the ProxyPass lines.
As far as I understand it, the server is trying to resolve the address literally, so when it checks for, say the docs page, which is in the webapps folder, it returns a proxy error that says that it can't resolve http://localhost:8080docs.

Apache Server Unable to host multiple domain on single Public IP Error : "Not Found The requested URL / was not found on this server."

Apache Server Unable to host multiple domain on single Public IP running on Windows Server 2016
Error:"Not Found The requested URL / was not found on this server." 404 Not Found
Progress so far :
1)Edited Windows hosts file "C:\Windows\System32\drivers\etc\hosts": to below
127.0.0.1 localhost
::1 localhost
127.0.0.1 koffeeroasters.com
2)Changes made in the httpd.conf file of apache is below
changed
#Include conf/extra/httpd-vhosts.conf
to
Include conf/extra/httpd-vhosts.conf
also changed
#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so
and added to the end of the file the following
# Tells Apache to identify which site by name
NameVirtualHost *:80
# Tells Apache to serve the default WAMP Server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wampstack/apache2/htdocs"
</VirtualHost>
# Tells Apache to serve Client 1's pages to "client1.localhost"
# Duplicate and modify this block to add another client
<VirtualHost 127.0.0.1>
# The name to respond to
ServerName koffeeroasters.com
ServerAlias www.koffeeroasters.com
# Folder where the files live
DocumentRoot "C:/wampstack/apache2/htdocs/koffeeroasters.com/"
# A few helpful settings...
<Directory "C:/wampstack/apache2/htdocs/koffeeroasters.com/">
Order Allow,Deny
Allow from all
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.html index.php
</VirtualHost>
Other details
I am using apache server on bitnami wampstack.
Site is available when typed the address "koffeeroasters.com" from the servers browser.
A reason for it which I know no solution of (refered from apache docs "https://httpd.apache.org/docs/2.4/vhosts/examples.html") :
Note :
Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries.
Thanks a bunch. All help appreciated.
Try changing this:
<VirtualHost 127.0.0.1>
to
<VirtualHost *:80>
This means allow any other IPs connect on port 80, which should get you going. Trying to match the localhost is doing more than you probably need, unless you are public facing server, in which case you will not want to do this.

Using httpd as reverse proxy

This is the first time I have to do something like this. I'm developing a front end application with some stuff I cannot change - it requests some specific address for the serverside data.
I need to redirect all those requests to say:
https://192.168.1.1:8443/server
to a different address, say
https://192.168.100.100:8443/server
I figured this is a job for Reverse Proxy and google brought me to httpd.
Now I work on Windows 7 machine, I've managed to get Apache24 binaries and started it on default 80 port, 127.0.0.1 says "It works!".
I tried to configure a virtual host but no matter what I do, I cannot get it to redirect.
I'm just trying to test the basic stuff first.
I've enabled required mods:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
I've uncommented following include:
Include conf/extra/httpd-vhosts.conf
And inside that file I got this:
<VirtualHost *:80>
ServerName mytest.com
ProxyPass /proxy/ http://myip:tomcatport/myapp/
ProxyPassReverse /proxy/ http://myip:tomcatport/myapp/
</VirtualHost>
I've looked through quite a few of tutorials on how to configure it and tried half a dozen different combinations of the same basic things, configured in this VirtualHost, but no matter what I do, I cannot get it to work.
From what I gathered, this configuration should redirect my browser from mytest.com to http://myip:tomcatport/myapp/, what am I doing wrong here?

Can it's possible to make multiple server in a same domain sub-directory

It's just my project. It's growing up and I want to add a new server as a sub-directory on the same domain. Is it possible to make sub-directory like:
example.com 127.0.0.1
example.com/project1/ 127.0.0.2
example.com/project2/ 127.0.0.3
How I config a DNS or Apache to make it work?
Sounds like you want to implement a proxy which can be done with mod_proxy. I assume the sites are already running on 127.0.0.2 and 127.0.0.3 and the public frontend is on 127.0.0.1
You will need to edit the configuration files on 127.0.0.1 and either in the main configuration (for a single site) or virtual host block for a virtual host, add the ProxyPass configuration:
ProxyPass /project1/ http://127.0.0.2/
ProxyPass /project2/ http://127.0.0.3/
This will send all requests from /project1/ to http://127.0.0.2/, if you want to keep this server hidden, or it's not accessible by the public such as an internal network address you will need to set up a reverse proxy so the results are fed back to users via your public front end, so you will need to add ProxyPassReverse configuration:
ProxyPassReverse /project1/ http://127.0.0.2/
ProxyPassReverse /project2/ http://127.0.0.3/
Further to this, you will need to enable the proxy modules in your configuration files as well, these are what I have enabled for a basic reverse proxy
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
There are some other modules that could be important depending on your situation
mod_proxy_connect This handles the CONNECT function if connecting to https:// servers
mod_proxy_ftp This handles connections to FTP servers
mod_proxy_ajp This handles connections to tomcat/AJP servers
mod_headers This can modify response and request headers
mod_deflate This negotiates compression with backends
mod_proxy_html This is a 3rd party module which will rewrite HTML links to the proxy address space