lighttpd rewrite script running on port to same domain for XSS? - apache

I am running freeNAS7 / lighttpd with some perl scripts that run on various ports localhost:5000, or localhost:8080 for example.
Now i tried to add cross-domian policy to the header but i cant get it to work, because most likley I am doing it incorrectly.I am not familiar with perl, if it were PHP then its pretty easy adding a header.(in terms of me understaning where to put it)
I was just thinking is there a way to rewrite for example something like
localhost/sabnzdb to display localhost:8080/ so that i can use client side to manipulate the iframe.

In lighttpd it's possible through mod_redirect. You can read about it here.
url.redirect = ( "^/sabnzdb$" => "http://localhost:8080" )
and put that in your localhost vhost (if you use vhosts) otherwise any place in your config should be ok.

Related

Neo4j not functional through apache proxy

I am able to run neo4j fine through port 7474 on my server including cypher queries. Though when I access neo4j through the apache proxy it will load just fine but any requests done through cypher will only return an "Unknown error". I have other proxies such as rstudio running just fine.
I have tried the default values on the neo4j website for proxy configuration with no success. I am at a loss for what to try. Please let me know for more information needed, or how I can get additional information on the cypher error.
I tried the sample Query:
CREATE (n {name:"World"}) RETURN "hello", n.name
And this returns "Unknown error" when done through the proxy, but when done through port 7474 it works fine
This is a Linux Ubuntu LTR 12.04.4 machine.
Neo4j 2.1.1
Apache 2.2.22
Sorry if this is vague but I have not found any help for this issue nor do I know what additional information would be relevant.
Thank you.
Update:
It now works with the case provided by Stefan (Thank you!). But I am unsure how to change it from being on the root of my domain to "/database/" in your example you can change it to "/neo4j" How would I change the other parts of this config file for this to function?
As it looks now (non functional with change of proxy from "/"):
ProxyPass /database/ http://localhost:7474/
ProxyPassReverse /database/ http://localhost:7474/
RedirectMatch permanent ^/database /database/
<Location /db/manage>
AddOutputFilterByType SUBSTITUTE application/json
Substitute "s|http://localhost:7474|http://localhost:8080|n"
</Location>
I tried to change the substitute rule from "localhost:8080" to "localhost:8080/database" and to "/database" to no avail.
In closing what worked is to make it a subdomain and still have it on the root. Not sure why this has to be the case, but it is functional. Thank you again Stefan!
Some time ago I've setup a example config for using mod_proxy and mod_substitute, see https://github.com/sarmbruster/vagrant_neo4j_modproxy. See esp the Apache config file.
Be aware that mod_substitute will not work with huge responses > 1M.

apache reverse proxy: how to forward proxy server's HTTP_HOST

Our local development setup requires a box in the DMZ, and each developer has a line in its apache config for proxying. Looks something like:
ProxyPreserveHost on
ProxyPass /user1/ {user1's IP}
ProxyPassReverse /user1/ {user1's IP}
ProxyPass /user2/ {user2's IP}
ProxyPassReverse /user2/ {user2's IP}
#etc
Our public URLs become {DMZ server}/user1, {DMZ server}/user2, etc. The problem is that on the dev's boxes, the value of $_SERVER['HTTP_HOST'] is just {DMZ server}, without the user's subdirectory. The desired behavior is to have /user%/ as the real host name.
I've tried overriding the HOST var, and some rewrite rules, but nothing has worked.
Creating subdomains is not an option.
thank you for any help!
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypreservehost seems to be the answer.
Im going to take a stab and suggest this:
SetEnvIf Host (.*) custom_host=$1
RequestHeader set X-Custom-Host-Header "%{custom_host}e/%{REQUEST_URI}e/%{QUERY_STRING}e"
That should hopefully set a request header called X-Custom-Host-Header that you can then pickup in PHP. If you want, you can try to override the Host Header, but I'm not sure on the implications of that. The Host header is a special HTTP header and generally only contains the host portion of an HTTP request, not the full request url.
Untested unfortunately, but it would help if you could clarify in a bit more detail what you are looking for.
EDIT, THIRD ANSWER:
Looks like Apache has heard this complaint before and the solution is mod_substitute. You need to use it to rewrite all the URLs returned in the document to insert /user1/.
EDIT, SECOND ANSWER:
Based on the additional information in your comments, I'd say your Apache config on your DMZ server is correct. What you are asking for is to have the developer machines generate URLs that include their context path (which is the J2EE term for something analogous to your /user1/ bit). I don't have any experience with PHP so I don't know if it has such a facility, but a quick search suggests it does not.
Otherwise, you'd have to roll your own function that converts a relative URL to an absolute URL, make that configurable so you can have it add something to the host name, and then force everyone to use that function exclusively for generating URLs. See, for some guidance, "Making your application location independent" in this old (outdated?) PHP best practices article for a solution to the related problem of finding local files.
PREVIOUS ANSWER: (doesn't work, causes redirect loop)
I'm still not clear what you are trying to do or what you mean by "Running on the dev apps are apache and PHP mainly, for hosting various applications", but as an educated guess, have you tried:
ProxyPass /user1/ {user1's IP}/user1/
ProxyPassReverse /user1/ {user1's IP}/user1/
If I were setting up the sort of environment you seem to be wanting to have, I'd want $_SERVER['HTTP_HOST'] to be {DMZ server} on every dev machine so that the dev machine's environment looks just like (or at least more like) production to the code running on it.

serve cache/html pages created by wp-super-cache using lighttpd

Currently I have lighttpd configured as a reverse proxy of apache. Lighttpd listens on the public IP while apache listens on 127.0.0.1. Lighttpd passes non-static contents to apache using the configuration
$HTTP["url"] !~ "\.(js|css|gif|jpg|png|ico|txt|swf|html|htm|gz)$" {
proxy.server = ( "" => (
( "host" => "127.0.0.1", "port" => 80 )))
expire.url = ( "/" => "access 5 minutes")
}
This simple setup works just fine with a vanilla wordpress install. Static files are being served by lighttpd while everything else is served by apache.
I want to take it to the next level so I installed wp-super-cache so that cache/html version of pages are created. The wp-super-cache plugin has been installed properly and its modification to the htacess file has been properly applied. I used the mod_rewrite mode of wp-super-cache and the custom permalink structure of wordpress is /%category%/%postname%.html. All works great. Cache/html pages are being created and served. There is just one little problem. It will only work if I remove the html file extesion in the above configuration. This means apache will serve the cache/html files and not lighttpd. One solution that I thought of is to have simliar rewrite rules on lighttpd when accessing html files. I do not know if it will gonna work but I searched for it anyway. I found http://tempe.st/2008/05/lightning-speed-wordpress-with-lighttpd-and-supercache-part-ii/ (you may need google cache to access it because it was not working today, but yesterday it did) thinking it may be the solution but the bad news is I am using a rpm based distro and the rpm repo that I use does not have mod_magnet for lighttpd. I searched for other repos that offer lighttpd with mod_magnet but found none. So I cannot use the one solution that I have found because my lighttpd does not have mod_magnet functionality.
What should I do to make lighttpd serve the cache/html files that were created by wp-super-cache? Is this possible?
Thanks!
I know, it's a little bit late, but you could try my version of rewrite.lua script for WP Super Cache. It works just like it must work. https://gist.github.com/1258096

custom mod_jk forwarding

i want to be able to forward url such as
http://external_url.com/auth => http://internal_url.com:8080/app/auth
https://external_url.com/w/my-account => https://internal_url.com:8080/app/LogIn.do
https://external_url.com/w/forgot-password => https://internal_url.com:8080/app/ForgotPassword.do
https://external_url.com/w/register-user => https://internal_url.com:8080/app/CustomerRegistration.do
http://external_url.com/w/logout => https://internal_url.com:8080/app/LogIn.do
I am already able to forward the standard mirror url to the tomcat apps, but unable to do so for the custom external_url, any ideas?
I tried using ProxyPathMatch:
ProxyPathMatch ^(/\/w\/forgot\-password)$ http://internal_url.com:8080 /app/ForgotPassword.do
but Apache complains saying its incorrect.
much appreciate for the help.
mod_jk isn't like mod_proxy in that you can rewrite the URL in this way. You can do something like this:
JkMount /auth myAuthApp
And then define in worker.properties the appropriate application:
worker.list=myAuthApp
worker.myAuthApp.host=internal_url.com
worker.myAuthApp.port=8080
But your tomcat application must be able to listen on the right context path. In this case it will be /auth, not /app/auth.
You can do all sorts of neat forwarding, using cookies, URIs and much more. But the application will still get the original path and must be able to respond to it.
http://tomcat.apache.org/connectors-doc/reference/apache.html

Redirect entire site with htaccess to other domain

I want to redirect entire site from one domain to other.
I works when i declare
RewriteRule with R=301 but user can easy notice that
he is redirected to other url in his navi bar.
The result i want to achieve is using remote server to display content
with url keeped from local server.
For example:
User types example1.com, the htaccess gets content from example2.com
(for main page and every subpage in example1.com). Server does not
redirect his browser but just loads remote data from example1.com.
It works when i just use file_get_contentes('example2.com... but
problem comes if there is some $_POST data.
The clean solution is to have the server that handles example2.com respond to requests sent to example1.com. This is usually done by configuring an Apache virtual host to use ServerName example2.com and ServerAlias example1.com.
If you cannot afford to do this, you should rely on an actual proxy-and-reverse-proxy instead of doing it yourself with PHP: it's faster, and it handles absolute URLs correctly (what happens if example2.com returns HTML that contains an <a href="http://example2.com/xxx"> ?). Apache has a correct proxy and reverse proxy implementation.
Not an answer to your question, but this solution is not optimal for a number of reasons:
It depends on two servers being up.
It is slower as the request has to be made twice.
It takes up double the bandwidth, and if you use a PHP script, additional resources on the proxying server.
Are you sure you have to do this?
If you really do, look into Apache's proxying capabilities instead of a PHP script that can deal with the problem you describe (and several others, for example session management, and passing through the HTTP_REFERER and HTTP_USER_AGENT variables). Here is a tutorial for it.
Note that this requires root access to the server.
I don't believe this is possible with .htaccess.
Could you not add example1.com as an alias in the httpd.conf for example2.com and change the DNS records for example1.com to point to the same machine as example2.com ?
That'll achieve what you are after and cuts out the middleman (example1.com's server).
You can't do such a redirect across domains using only mod_rewrite. A rewriterule that writes to an address on another server will always behave as if it has an R flag.
You'll probably have to use some server-side scripting, not sure how though.
I solved it by using:
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => (isset($_POST)) ? http_build_query($_POST) : '',
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://example2.com/'.$_SERVER['REQUEST_URI'], false, $context);
I realise that is quite lame solution but it works well.