How to configure Apache to proxy exactly one file? - apache

(I must be dense - I just can't figure out the Apache documentation on how to do this.)
To speed up some swf development I'm doing, I want to have my local machine fetch my local swf when I browse to our studio's test website. Just the one local swf only - with the rest pulled from the test website.
So I set up apache on port 80 with mod_proxy and proxy_http_module, then added an entry for HOSTS to say the test server is 127.0.0.1. What I need are the magical incantations to put in httpd.conf to say "every call requesting http://test/blah goes to 10.1.1.whatever EXCEPT http://test/blah/foo.swf which goes to c:\proj\foo.swf".
Can someone help with this? Thank you.

There is a simple syntax for disallowing a particular URL from proxying:
ProxyPass /blah/foo.swf !
ProxyPass /blah http://10.1.1.whatever

For the record here's what I ended up with, roughly:
<VirtualHost *>
ServerName (testserver-dns)
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /path/to/swf !
ProxyPass / http://10.1.2.3/
ProxyPassReverse / http://10.1.2.3/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>

Related

Apache config api endpoint

I am running a vue js application as a v-host (app.test.com) on
http://app.test.com
The backend is a go application (which implements a webserver on its own) and is running on
http://localhost:8000
Is it possible to configure apache to redirect/proxy all request that go to http://app.test.com/api to http://localhost:8000 ?
Let's say i call http://app.test.com/api/endpoint1 from the vue application i'd like it to be proxied to http://localhost:8000/api/endpoint1.
I normaly have a dedicated dns for the api and using this config then in the v-host:
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://0.0.0.0:8000/
ProxyPassReverse / http://0.0.0.0:8000/
which works good.
But i can't figure out how to use this in a allready defined v-host.
Any hints/examples?
Many thanks
Sorry for this question. Managed to run this .. forgot to add the Proxy * directive to the config...
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /api/ http://0.0.0.0:8000/api/
ProxyPassReverse /api/ http://0.0.0.0:8000/api/
does it all, if someone Needs this

Apache Proxy balancer overuling file access limits

I have 1 load balancer server and 2 app servers which do load distribution. Now i have a strange problem that the
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
rule dous not get triggerd when the request gets forwarded to the app servers.
Setup is:
<Proxy balancer://catdefault>
BalancerMember http://xx.xxx.xxx:8081
BalancerMember http://xx.xxx.yyy:8081
</Proxy>
And in the virtual host i get it included like this:
ProxyPass / balancer://catdefault/
ProxyPassReverse / balancer://catdefault/
The strange thing is that when i apply the Files rule in the app server which is a balance memger ex. http://xx.xxx.xxx:8081 then the rule gets respected.
Now we agreed not to makie rew rulles on the app server because they will be later or many of them and administration will be heavy.
Any idea how i can make the files work from the load balancer server and not the http://xx.xxx.xxx:8081 servers???
<Directory> or <Files> directives will only apply to objects that reside in the filesystem.
Perhaps something like this can help (untested):
ProxyPassMatch "(?i)\.ht([^/]*)$" !
ProxyPass / balancer://catdefault/
ProxyPassReverse / balancer://catdefault/

Running Jenkins behind Apache 2.2 issue

I need to configure Jenkins behind Apache. For this purpose I installed Apache 2.2 using httpd-2.2.25-win32-x86-openssl-0.9.8y.msi.
Now I have configured jenkins with -
--httpPort=8084 --prefix=/jenkins (inside jenkins.xml)
The securityRealm for Jenkins is (I am using LDAP authentication):
<securityRealm class="hudson.security.LDAPSecurityRealm" plugin="ldap#1.11">
<server>ldap://ldap.myserver.com:1234</server>
<rootDN>DC=blah-blah,DC=blah</rootDN>
<inhibitInferRootDN>false</inhibitInferRootDN>
<userSearchBase></userSearchBase>
<userSearch>SAMAccountName={0}</userSearch>
<groupSearchFilter></groupSearchFilter>
<groupMembershipStrategy class="jenkins.security.plugins.ldap.FromGroupSearchLDAPGroupMembershipStrategy">
<filter></filter>
</groupMembershipStrategy>
<managerDN>email#mycompany.com</managerDN>
<managerPasswordSecret>XXXX</managerPasswordSecret>
<disableMailAddressResolver>false</disableMailAddressResolver>
<displayNameAttributeName>displayname</displayNameAttributeName>
<mailAddressAttributeName>mail</mailAddressAttributeName>
<userIdStrategy class="jenkins.model.IdStrategy$CaseInsensitive"/>
<groupIdStrategy class="jenkins.model.IdStrategy$CaseInsensitive"/>
</securityRealm>
The name of the server where Apache and Jenkins are hosted is : http://abchost/.
Jenkins is hosted at : http://abchost:8084/jenkins.
Now I need to configure Apache server in such a way that, when I enter http://abchost/jenkins in browser it a Proxy should work in between and it should forward the request to http://abchost:8084/jenkins and again, get the result from jenkins and display the result at : http://abchost/jenkins.
For this I have configured Apache like this:
NameVirtualHost abchost:80
Listen 80
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes On
<VirtualHost *:80>
ServerName abchost.com
ServerAdmin admin#abchost.com
ProxyPass /downloads !
Alias /downloads "d:\myPath1"
<Directory "d:\myPath2">
# Don't allow editing the main repository site.
Options -Indexes
</Directory>
<Directory "d:\myPath3">
# Remove 'Parent Directory' link from the site.
# IndexIgnore ..
#
Options +Indexes
# List file names which will be opened automatically when the folder is opened.
DirectoryIndex index.html toc.html
IndexOptions FancyIndexing HTMLTable FoldersFirst SuppressDescription
</Directory>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Jenkins via HTTP.
ProxyPass /jenkins/ http:/abchost:8084/jenkins/ nocanon
ProxyPassReverse /jenkins http://abchost:8084/jenkins/
</VirtualHost>
After this configuration, I am able to login in jenkins using http:/abchost:8084/jenkins/, but, not using http:/abchost/jenkins/.
Point to note is:
When I am logging in http:/abchost/jenkins/ using proper user id and pswd, it looks like the page refreshes and blank login page appears again.
When I am logging in http:/abchost/jenkins/ using wrong user id and pswd combination, it shows message that LDAP authentication failed.
Can anyone please enlighten me?
Thanks in advance!

Running multiple root\no context web apps on single host

I have a host with a single web app and at the moment I am accessing it via www.hostnameA.com/ as the web app is deployed to tomcat/webapps as the tomcat ROOT web app.
Now I need to add another web app to my host and I also want this one to have no context either but will access it via another hostname www.hostnameB.com/ but I can only deploy one ROOT tomcat web app.
I should have added that I am using apache as well and my virtual host looks like:
<VirtualHost *:80>
ServerName www.hostnameA.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
I tried renaming the war file to webAppA and then appending that to the proxypass but it gave me a 400 error and kept appending /webAppA to the URL:
ProxyPass / http://localhost:8080/webAppA
Is there a solution to this? I dont really want to run multiple instances of tomcat on different ports just for this, is there another option?
As discussed above, most straightforward solution would be to use Apache's mod_proxy_ajp, allowing proxying and AJP forwarding at the same time. Configuration should look something like:
<VirtualHost *:80>
ServerName www.hostnameA.com
ProxyPass / ajp://localhost:8009/webAppA/
ProxyPassReverse / http://www.hostnameA.com/webAppA
[...]
...and same with B for www.hostnameB.com.

getting node.js app to work on port 3001

ok, this one is confusing me greatly!
If I add this to my apache conf:
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /node>
ProxyPass http://localhost:3001/
ProxyPassReverse http://localhost:3001/
</Location>
now, when I go to .../node, i see the following page:
"Welcome to socket.io."
But what I want to happen, is to see that page by typing in website:3001, but this just doesn't work. Why might this be?
Addiitional:
The server has a private IP, to which the router forwards IP traffic on ports 3000 and 3001. I can load the page using curl or wget using the private IP, but not the public IP. Any ideas why this might be?