Apache ProxyPass not loading Resources
After some research and reading some tutorials I got a solution.
<VirtualHost *:80>
ServerName app.server.com
DocumentRoot /var/www/html/subdomain
RewriteEngine on
ProxyRequests Off
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass / http://192.168.1.102:9999/
ProxyPassReverse / http://192.168.1.102:9999/
</VirtualHost>
Apache proxypass does not resolve url for resources like images and css
After a lot of trial and error, I found two different solution to my problem.
Using mod_rewrite and some changes to proxypass:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /app http://localhost:8080/ui/
ProxyPassReverse /app http://localhost:8080/ui/
#since in java web app the context started with /ui the js src had /ui in the beginning
#this resulted in 404 so I had to rewrite all request to /ui to forward to /app
RewriteEngine on
RewriteRule "^/ui(.+)" "/app$1" [R,L]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>Create a link/shorcut to deployed application inside webapp folder and name the shorcut as app
In linux the command is(from inside webapp folder)ln -s ui app
Now the apache config is:
<VirtualHost *:80>
ProxyPreserveHost On
<Location /app>
ProxyPass ajp://localhost:8019/app/
ProxyPassReverse ajp://localhost:8019/app/
SetOutputFilter proxy-html
ProxyHTMLExtended On
ProxyHTMLURLMap /app /app
RequestHeader unset Accept-Encoding
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
In the first solution the rewrite mod causes request to return 304 before redirecting to correct url. That is how it works by default.
In the second solution since both handlers are same(/app) there is no reason for redirection and the URL's are mapped correctly.
Apache Proxy pass and static resources
If your content isn't happy being served from anything but under /, it's not proxy friendly. You could use mod_rewrite to check HTTP_REFERER and add the /app1 prefix back in prior to your proxy rules.
Loading of Core Scripts Fail When Using Apache for Next.js Reverse Proxy
Here is a workable solution:
Create a next.config.js file that looks like this:
module.exports = {
basePath: '/test',
}
Now modify your localhost proxy entry in Apache's VHost conf file to reflect the changes to the basePath as such:
<Location "/test">
ProxyPreserveHost On
ProxyPass http://localhost:2301/test
ProxyPassReverse http://localhost:2301/test
</Location>
This will ensure that the "virtual directory" and the directory that next.js uses as the project root are the same and the proxy works as intended. I like to use the <Location>
tag to define the scope of the proxy in case I need to add any Rewrite or Redirects or exclusions therein. Notice the use of the Location tag changes the syntax of ProxyPass and ProxyPassReverse
Related Topics
Any Reason for Using "*/" in Command "Ls -D */" to List Directories
Why Doesn't Set -E Cause a Failure with 'False || False && True'
Why Ln -Sf Does Not Overwrite Existing Link to Directory
How to Identify the User Who Owns a Process from /Proc/Pid
How to Display Filename from a Column Using Awk
How to Use a Samba Server Location for Gopath
How to Stop Apache from Listing the Contents of My User Directories
Linux Zip and Exclude Dir via Bash/Shell Script
Shell Script to Create Empty Files with All Possible Permissions
Problems with Accessing Command Line Arguments in Linux from X86 Asm
Knowing If a Remote Port Forward Was Successful
/Var/Log/Daemon.Log Taking More Space How to Reduce It
How to Print the Nth (5Th) Line of Every File Preceded by the Filename Using Any Linux Tool
Mathematical Expression Result Assigned to a Bash Variable
Bash: Checking If Files Are Duplicates Within a Directory
How to Merge Similar Lines in Linux
Can Someone Explain How This "Shellshock" Code Works in Shell