I am trying to reverse proxy just the homepage on a website - trying to use the rules below. Basically I have an alternate page that I want the content to be server from but I still want the original URL for the site to display with the content from the reverse proxy. Both pages are in the same domain - the only difference is one is www.domain.com while the other page is www2.domain.com
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
ProxyPass http://www.domain.com http://www2.domain.com/
ProxyPassReverse http://www.domain.com http://www2.domain.com/
When I put in rules above it does not work - can somebody show where Im going wrong please ?
The first argument for ProxyPass and ProxyPassReverse is a path, the correct syntax for your directives would be
ProxyPass / http://www2.domain.com/
ProxyPassReverse / http://www2.domain.com/
But that would proxy all your requests. Try
#disable forward requests
ProxyRequests Off
#allow proxy requests
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
#reverse proxy
RewriteEngine On
RewriteRule ^/?$ http://www2.domain.com/ [P,QSA,L]
If the proxying fails, you server error.log may tell you what happens. Or add a log for the mod_rewrite, it will tell you why it doesn't capture the request
RewriteLogLevel 5
RewriteLog /path/to/a/file
Related
I am setting up a reverse proxy with apache for a program that uses kestrel.
I attempted in httpd.conf:
<Location /asf>
ProxyPass http://localhost:1242/
ProxyPassReverse http://localhost:1242/
RewriteEngine On
RewriteRule ^asf/$ http://localhost:1242/$1 [R=301,L]
</Location>
and in .htaccess, placed in htdocs (root of site):
RewriteEngine On
RewriteRule ^asf/$ http://localhost:1242/$1 [R=301,L]
however neither of them has worked.
<Location /asf>
ProxyPass http://localhost:1242/
ProxyPassReverse http://localhost:1242/
</Location>
by itself in httpd.conf works without problems, but however api requests do not make it to the desired location.
I expect requests sent to example.com/asf/api/X to go to localhost:1242/api/X.
In addition to this, /api/NLog is a websocket, if that matters.
I am using Crafter CMS with multi-tenancy. I am trying to setup Apache2.4 on RHEL7 to be a reverse proxy. http://site.example.com -> ajp://localhost:9009/?crafterSite=site
Here is my Apache2 virtual host configuration. I have ensured that mod_proxy and mod_rewrite are loaded. I can reach Crafter Delivery through the proxy but the rewrite isnt working as Crafter doesnt know what site I am trying to load. Does anyone have any suggestions on how to get this working.
<VirtualHost *:80>
ServerName site.example.com
LogLevel alert rewrite:trace3
RewriteEngine On
RewriteRule ^$ /?crafterSite=site [QSA,L]
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / ajp://localhost:9009/
ProxyPassReverse / ajp://localhost:9009/
</VirtualHost>
Try changing the rewrite rule to be:
RewriteRule (.*) $1?crafterSite=site [QSA,PT]
Where site is your site ID.
The differences are:
It rewrites anything coming in regardless of URL and preserves it (see the (.*) and $1)
It's a passthrough PT (not a redirect). This means it augments the request with the param and lets it straight through to Crafter Engine.
I've a domain which is using 2 separate virtualhost files: one for :80 and one for :443
The :80 setup is pretty easy, it's only job is to redirect to :443:
<VirtualHost *:80>
# This is the first host so it's the default.
# So although I've specified a ServerName and ServerAlias anything else not specified elsewhere will also end up here.
ServerName www.domain.com
ServerAlias domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Redirect everything to https:
RewriteEngine on
RewriteRule ^(.*)$ https://www.domain.com$1 [R=301,L]
</VirtualHost>
The :443 simply needs to add www to the beginning of the url if it was absent:
<VirtualHost *:443>
# This is the first host so it's the default.
# So although I've specified a ServerName and ServerAlias anything else not specified elsewhere will also end up here.
ServerName www.domain.com
ServerAlias domain.com
ErrorLog ${APACHE_LOG_DIR}/ssl.error.log
CustomLog ${APACHE_LOG_DIR}/ssl.access.log combined
# Redirect everything which is not already on the real www domain name to that:
RewriteEngine on
RewriteCond %{HTTP_HOST} !www.domain.com
RewriteRule ^(.*)$ https://www.domain.com$1 [R=301]
ErrorDocument 404 /404.html
</VirtualHost>
I've 1 case in which these Rewrites seem to fail:
https://domain.com -> should point to https://www.domain.com but it points to https://www.domain.com%24/# . Obviously the characters at the back prevent the DNS server from finding the domain.
What is causing this issue? I've already had helped creating these virtualhosts files but it seems they're still not fully working as expected.
BUT I also want to rewrite my URLs to nicer ones. I think my rule is correct and the Rewrite block in :443 looks like the following
RewriteEngine on
RewriteCond %{HTTP_HOST} !www.domain.com
RewriteRule ^(.*)$ https://www.domain.com$1 [R=301]
RewriteRule ^subpage/(.+)/?$ subpage.html?$1 [NC]
Which should rewrite
https://www.domain.com/subpage/2 -> https://www.domain.com/subpage.html?2 but it's just pointing towards my 404 file now.
It might be something obvious, but I'm not seeing my mistake.
NOTE: This doesn't solve the problem as stated here, but it does solve the underlying problem.
As this is a production environment (how awkward.) my webserver, which was pretty weak to start with, got flooded rather quickly. My company greatly increased my budget (we were expecting a lot of traffic, but were hoping it would build up slowly which it didn't) so I was able to set up multiple servers and placed 2 HAProxy loadbalancers in front of them. I used the HAProxy configuration to solve my problems using:
frontend http
bind MY_IP:80
redirect prefix http://www.domain.com code 301 if { hdr(host) -i domain.com }
redirect scheme https code 301 if !{ ssl_fc }
frontend https
bind MY_IP:443 ssl crt /etc/haproxy/certs/domain.com.pem
redirect prefix https://www.domain.com code 301 if { hdr(host) -i domain.com }
reqadd X-Forwarded-Proto:\ https
default_backend app_pool
backend app_pool
balance roundrobin
redirect scheme https if !{ ssl_fc }
server app-1 MY_IP:80 check
server app-2 MY_IP:80 check
server app-3 MY_IP:80 check
server app-4 MY_IP:80 check
which will always redirect to the www.domain.com version and enforce HTTPS as well. Setting this up in HAProxy is way easier than using VirtualHost in my opinion.
iv'e been looking through and am trying to find a solution to force HTTPS on apache-reverse-proxy behind AWS ELB without success.
my sites-enabled config file looks like this.
<VirtualHost *:80>
ServerAlias *.domain.net
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} http
RewriteRule https:// %{SERVER_NAME}%{REQUEST_URI} [R=301,L]
ProxyPass / http://{10.10.10.21}/
ProxyPassReverse / http://{10.10.10.21}/
</VirtualHost>
however i never get any redirect back to the browser when i hit the server on port 80. the proxypass and reverse are kicking in, but not the redirect.
i see that by enabling rewrite-trace level 8 as follows:
ive been on this for too long now....
any help will be greatly appreciated!
I have a SSO url -
http://<server>/<junction>/<application_context>/ssoLogin.do
e.g. http://pingu.intranet.com/tms/mint/ssoLogin.do
Once user hits this url. SSO junction appends headers and redirects to Apache webserver. My goal is to remove the SSO junction name once the request reaches Apache(where I am using ProxyPass and AJP to connect to Tomcat App).
Issue is mod_rewrite is picking the URI - /mint/ssoLogin.do. so I can not remove the junction name /tms. e.g. rewrite.log says
init rewrite engine with requested uri /mint/js/jquery/jquery.min.js
My conf file looks like
ProxyPreserveHost On
# define the balancer, with http and/ or ajp connections
<Proxy balancer://application_cl>
BalancerMember ajp://pingu01.intranet.com:8009 route=node1 disablereuse=on retry=0
BalancerMember ajp://pingu02.intranet.com:8009 route=node2 disablereuse=on retry=0
</Proxy>
# Vendor Product ProxyPass Settings
ProxyPass /mint balancer://application_cl/mint stickysession=JSESSIONID|jsessionid nofailover=On
ProxyPassReverse /mint balancer://application_cl/mint
# Custom settings to remove junction name for proper javascript loading
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/tms/
RewriteRule ^/tms/(.*) /$1
</IfModule>
# RequestHeader settings(as per Product documentation)
SetEnvIf X-Forwarded-Proto .+ HAVE_X_FORWARDED_PROTO
RequestHeader set X-Forwarded-Proto "http" env=!HAVE_X_FORWARDED_PROTO