ProxyPass worker name (*long url here*) too long - apache

I have a URL www.example.com.
This should point to the page
www.data.city.author/blah/blah/fjfjf/fkkeklf/eied/shudfj
and show the content in
www.data.city.author/blah/blah/fjfjf/fkkeklf/eied/shudfj
but in the address box, it should show www.example.com
My present configuration in vhost.conf for the proxy is:
SSLProxyEngine on
Proxypass "/" www.data.city.author/blah/blah/fjfjf/fkkeklf/eied/shudfj
ProxyPassReverse "/" www.data.city.author/blah/blah/fjfjf/fkkeklf/eied/shudfj
The Problem is that Apache 2.4 has a bug that when using ProxyPass, URL should not be more than 96 characters. So it is truncating the URL to 96 characters and hence the configuration is returning with an error message.
Any other way to solve my case. I tried using apache RewriteRule with [P] flag but it does not work in my case.
EDIT
Below is my present configuration
<VirtualHost *:11080>
ServerAdmin webmaster#dummy-host.example.com
ServerName int.chicagomeningvax.org
ServerAlias www.int.chicagomeningvax.org
DocumentRoot "/app/web-vhosts"
ErrorLog "/app/apache-vhosts/logs/error_log"
CustomLog "/app/apache-vhosts/logs/access_log" combined env=!dontlog
RewriteEngine on
RewriteRule / https://data.cityofchicago.org/Health-Human-Services/Meningitis-Vaccine-Locations-Map-Visualization/n4bi-r8ij [R=302,P]
</VirtualHost>

If your url is too long please use Alias instead, it worked for me.
In your mod_proxy.conf file:
Alias http://dummy:8009 http://yourlongoriginalurl:8009
Proxypass / http://dummy:8009

Related

www.api.domain.com leads to one page and api.domain.com leads to another. www.domain.com works but domain.com doesn't. What gives?

I have the following Apache virtual hosts config file called 000-default.conf
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /var/www/mydomain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:80>
ServerName api.mydomain.com
ProxyPreserveHost On
ProxyPass / http://xxx.xx.xx.xx:3000/
ProxyPassReverse / http://xxx.xx.xx.xx:3000/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I am facing the 2 following issues and I'm not sure if the problem is on Apache's side or on the DNS's side:
When I visit www.mydomain.com , I see the page that I am supposed to
be seeing but if I try typing just domain.com in the search bar, I
get an error - This site can’t provide a secure connection
When I visit api.mydomain.com , I see the correct page which I'm
supposed to be seeing BUT when I try www.api.mydomain.com , I get
the page that is supposed to be on www.mydomain.com instead.
Can anyone shine some light on whether this is a result of bad Apache configuration or I need to do something on the DNS?
You would need to add two lines to your /etc/apache2/.conf
ServerAlias www.domain.com
Add this line under the ServerName

Setup crafter cms studio for access via apache web server proxy and ajp connector

I need to setup crafter cms studio within the authoring part to be able to access from remote host (e.g. VPS). I'm using Tomcat ajp connector via Apache web server proxy.
I've tried do it like adding the virtual host:
<VirtualHost *:80>
ServerName studio
DocumentRoot /home/web-apps/crafter/bin/apache-tomcat/webapps/studio
RewriteEngine On
ProxyPreserveHost On
# Send requests to Engine's Tomcat
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
# This is where errors related to this virtual host are stored
ErrorLog logs/mysite-error.log
# This is where access logs are stored
CustomLog logs/mysite-access.log combined
</VirtualHost>
But not really succeeded. I can see only the default page which always tells me: "Crafter CMS has no site configured for this domain. Please configure the site you want to show or select a site on the authoring environment." when I'm requesting it like http://my_remote_host_ip/studio
Anyone has ever challended problem like this?
What you have looks right. Perhaps you can try:
clearing your cookies for my_remote_host_ip
clearing your browser cache
removing DocumentRoot directive (not really needed in this particular case)
This works for me:
<VirtualHost *:80>
ServerName myserver
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
ErrorLog ${APACHE_LOG_DIR}/authoring-error.log
CustomLog ${APACHE_LOG_DIR}/authoring-access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName myserver
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/my.crt
SSLCertificateKeyFile /etc/apache2/ssl/my.key
SSLCertificateChainFile /etc/apache2/ssl/their.crt
ProxyPreserveHost On
# Studio
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
ErrorLog ${APACHE_LOG_DIR}/authoring-error.log
CustomLog ${APACHE_LOG_DIR}/authoring-access.log combined
</VirtualHost>
Another approach is to try the community edition on AWS and see if that works with your browser. Then you can look at how that's configured and copy the config: https://aws.amazon.com/marketplace/pp/B08374YPTP?qid=1581949339014&sr=0-2&ref_=srh_res_product_title

About Apache Rewrite Function to Shorten URL

I have an URL "http://10.21.50.66:8123/test/file/index.htm" which hosted in Apache server. I would like to shorten the URL to just "http://10.21.50.66:8123/" and I managed to do it by using Rewrite function in httpd.conf. However, when I type "http://10.21.50.66:8123/" in browser, it will redirect and the URL of the browser will change back to the long url "http://10.21.50.66:8123/test/file/index.htm". What I would like to archive is that when every time I type "http://10.21.50.66:8123" in browser, the browser will open "http://10.21.50.66:8123/test/file/index.htm" but the URL on the browser will still showing "http://10.21.50.66:8123/". Below is the currecnt setting:
RewriteEngine On
RewriteRule ^/$ http://10.21.50.66:8123/test/file/index.htm [R,L]
Any ideas?
Thanks in advance.
If you use [R], the Apache will return response code 302 to the browser (with the new Location), which will cause that new URL to appear in address bar.
try:
RewriteEngine On
RewriteRule ^/$ /test/file/index.htm [L]
You need to create a virtual host in httpd.conf. You might find it in extras folder too as httpd.vhosts.conf Its something like this:
<VirtualHost *:80>
ServerAdmin admin#test.com
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/test.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
you need to write something like:
<VirtualHost 10.21.50.66:8123>
ServerAdmin admin#test.com
ServerName test.com
ServerAlias www.test.com
DocumentRoot [path to your test/file folder]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

apache RewriteRule and proxypass

I am in the process of setting up a jira server and will use apache to be a proxy to the tomcat service. I have my apache setup 90% completed but can't workout the final configuration. The goal is to have users be able to access the FQDN, the alias or the fully qualified alias but the URL is always rewritten to the DNS alias. e.g user browses to:
http://jira.domian.com rewrite to https://jira
http://nbsrvjira-07v rewrite to https://jira
http://nbsrvjira-07v.diasemi.com rewrite to https://jira
All the above work however the below fail:
https://jira.domian.com rewrite to https://jira
https://nbsrvjira-07v rewrite to https://jira
https://nbsrvjira-07v.diasemi.com rewrite to https://jira
Unless a specific URL is used it will cause issue within the application, the apache configuration is below:
The http to https redirect:
<VirtualHost *:80>
ServerName nbsrvjira-07v.domain.com
ServerAlias jira-test jira-test.domain.com
ErrorLog "/var/log/httpd/nbsrvjira-07v.domain.com_error.log"
ServerSignature Off
CustomLog "/var/log/httpd/nbsrvjira-07v.domain.com_access.log" combined
RewriteEngine On
RewriteRule ^/(.*) https://jira-test/ [noescape,last,redirect=302]
</VirtualHost>
The https to proxy pass:
VirtualHost *:443>
ServerName nbsrvjira-07v.domain.com
ServerAlias jira jira.domain.com
ErrorLog "/var/log/httpd/nbsrvjira-07v.domain.com_error.log"
ServerSignature Off
CustomLog "/var/log/httpd/nbsrvjira-07v.domain.com_access.log" combined
SSLEngine On
SSLCertificateFile "/etc/pki/tls/certs/nbsrvjira-07v.domain.com.cert"
SSLCertificateKeyFile "/etc/pki/tls/private/nbsrvjira-07v.domain.com.key"
RewriteEngine On
ProxyPass / http://localhost:8080/ connectiontimeout=5 timeout=300
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
I have tried various rewrite rules within the https configuration but none seem to work. Can someone help?
Chris
Maybe set up more than one VirtualHost for *:443 where one or more will just redirect to https://jira and only one will act as https://jira and contain the proxying? Just a guess.

Apache mod-proxy ProxyErrorOverride for specific URL patterns

I am using Apache 2.2 with mod-proxy and I have configured it with several ProxyPass statements to proxy from remote URL to local URL. I need to have custom error documents returned from Apache for these proxied URLs so I set "ProxyErrorOverride On" in my mod-proxy configuration along with some ErrorDocument directives (with local URL path) to return custom error pages for a few HTTP status codes of interest. However, when a status code is returned for which I have NOT created an ErrorDocument directive for, Apache replaces the response body with a default error page instead of leaving the original response body intact. This won't work with the application. So I really have 2 questions:
1) Is it possible to configure Apache to leave the original response body intact for a particular status code if I don't have an ErrorDocument override defined for it?
2) Is it possible to have the ProxyErrorOverride directive only apply to some of the URLs in my ProxyPass statements?
As arober11 pointed out in the comment above:
Afraid the answer is: No and No. If the directive could be limited to
a location, directory, or set of URL's, then there would be something
in the "Context" section, of the man page:
httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxyerroroverride
on the other hand: you can always add it to mod_proxy.c yourself.
For question 2:
Definitely doable. Using internal redirects to either new host or port this is possible. Brief outline using hosts (add noErrorOverrideUrl,doErrorOverrideUrl in DNS or /etc/hosts of apache-machine):
NameVirtualHost *:80
<VirtualHost *:80>
RewriteEngine On
RewriteRule ^(/noErrorOverrideUrl/.*) http://noErrorOverrideUrl$1 [L,P]
RewriteRule ^(/doErrorOverrideUrl/.*) http://doErrorOverrideUrl$1 [L,P]
</VirtualHost>
<VirtualHost *:80>
ServerName noErrorOverrideUrl
ProxyErrorOverride Off
ProxyPass ...
...
</VirtualHost>
<VirtualHost *:80>
ServerName doErrorOverrideUrl
ProxyErrorOverride On
ProxyPass ...
...
</VirtualHost>
Brief outline using ports:
Listen 80
Listen 81
Listen 82
<VirtualHost *:80>
RewriteEngine On
RewriteRule ^(/noErrorOverrideUrl/.*) http://server:81$1 [L,P]
RewriteRule ^(/doErrorOverrideUrl/.*) http://server:82$1 [L,P]
</VirtualHost>
<VirtualHost *:81>
ProxyErrorOverride Off
ProxyPass ...
...
</VirtualHost>
<VirtualHost *:82>
ProxyErrorOverride On
ProxyPass ...
...
</VirtualHost>
You can upgrade apache and use the If sentence avaible on 2.4+
<VirtualHost *:80>
...
<If "%{REQUEST_URI} =~ m#^\/QA(.*)$#">
ProxyErrorOverride Off
</If>
..
</VirtualHost>
Documentation