Trying to reverse proxy and password protect an application, but having issues with rewriting URLs and password protection not working
My server is a Raspberry Pi running Raspbian. I have an application that has a web interface, but instead of having authentication it only allows connections from localhost. The documentation said to reverse proxy it if I want to access it on another device. What I'm trying to do is:
1. Reverse proxy connections from example.com/application/url (where example.com is my server address. I don't actually have a domain name because I'm cheap) to localhost:3000/url 2. The application uses relative URLs. I want to rewrite those into absolute URLs for the reverse proxy. For example, one line of the HTML from example.com/application might be <script src="app.js"></script>. Normally, this would access example.com/app.js, not /application/app.js. I want it rewritten to <script src="example.com/application/app.js"></script> to address that. It also has several locations where it is hardcoded to open files or websocket connections to localhost:3000 that I want fixed. 3. Password protect the application because I don't want it accessible to the public. I was able to get the reverse proxying working perfectly fine, but I wasn't able to get the URL rewriting or password protection working. I've added Code:
<Location /application> Code:
<Directory "/var/www/html/application"> I don't see anything wrong with my configuration, but I also have no real idea of how to use an Apache web server. |
|
That fixed the authentication issues I was having, but my URL rewriting still is not working.
|
Quote:
Quote:
|
I'm pretty sure I am.
|
I'm going to bump this. I have now successfully password protected my application, but after hours of research, I still cannot figure out why URL rewriting is not working. My /etc/apache2/apache2.conf contains
Code:
<Location /application> |
Once again, may I ask why don't you use just "/" instead of "/application" for your application? E.g:
Code:
<Location /> Since I'm not familiar with mod_proxy_html, according to this, I guess that the following should work (again mind the trailing slashes!). Code:
<Location /application/> |
I thought that you were saying <Location /> as an abbreviation for both the opening and closing tags without caring about the content. I often see XML tags referred to that way. By my original interpretation (which your more detailed explanation has proven to be incorrect), you were suggesting exactly what I was already doing. I insist on using /application rather than just / because I have multiple applications running on my server, and I don't want to have to remember and forward all of the ports. /application is an example, and I'm assuming that I can copy-paste it into the config and replace "/application" with a more useful URL and repeat for all of my applications. I want to save the root for either a list of the URLs in case I forget or a redirect to my real website in case someone finds my home server while looking for it. (My home internet is not fast enough to host a public website (10 megabit down/1 megabit up), so I'm putting that on Gitlab Pages.) My config file now contains
Code:
<Location /application> 1. Even though you said that the trailing slashes were important, my application doesn't work at all unless I don't have trailing slashes on http://localhost:3000. With the local slashes, I get a page that says "Malicious Path" and nothing else. Without the trailing slashes, it works pretty much as expected. 2. ProxyHTMLURLMap /application /application had to be replaced with ProxyHTMLURLMap http://localhost:3000 /application. I figured out that ProxyHTMLURLMap basically scans the HTML for references to the first path and replaces them with references to the second. ProxyHTMLURLMap / /application replaces the root with /application, so it handles all relative requests and works fine. ProxyHTMLURLMap /application /application looks like it will only correct URLs that have already been corrected, so I replaced it with my line that according to the article corrects absolute URLs. 3. I added the ws:// one in an attempt to proxy websocket requests as well because my application uses those. This seems to have fixed all of my URL issues in the HTML files, but it did not do anything to Javascript files. Those still make requests to localhost:3000 rather than the proxy. Unfortunately, now I can't figure out how to do the same thing to Javascript files. Is there a ProxyJSURLMap? |
Quote:
Quote:
Re. the javascript files, try this: Code:
RewriteEngine on |
Quote:
|
Quote:
|
I have no idea how to do that, but I'm willing to learn. I might also just be lazy and use Python to do it. However, this solution has two problems:
1. Forums and developer communities often do not want to support versions of the software that have been modified. 2. This particular application uses node and is run directly from the Git repository, so it should be easy to modify, but in the future I might have to do the same thing for an application that I don't have the source code for. For example, I've seen some embedded devices with web interfaces and it's imaginable that a proprietary app might have the files being served compiled in. If you are unable to help with this, do you know of any other places I can go? |
Quote:
Anyway if you don't want to modify the code, you could ask the application developers for support. Regards |
All times are GMT -5. The time now is 11:36 PM. |