Apache reverse proxy and infinite loop - wordpress

I have Server A and B. Server A hosts the main site www.example.com, Server B hosts another site using the subdomain test.example.com. On Server A I set up a reverse proxy, so that the Wordpress site running on test.example.com can be accessed via www.example.com/test
Now I want the subdomain test.example.com to be "invisible" for the user, so that a request to test.example.com will redirect to www.example.com/test.
Obviously, this got me into an infinite loop. I tried different things to break the loop to no avail.
Is there a way to do this?

<VirtualHost *:80>
ServerName test.example.com
RedirectMatch permanent ^/(.*) www.example.com/test
</VirtualHost>
Add the above apache conf and restart apache.

Related

Redirect http to htps on apache2 vhost behind aws ELB

I have a small problem with redirecting everything from http to https.
Here is the setup of my environment:
The server is a docker host which runs multiple docker containers. I'm trying to access a container that listens on port 9000. so I have a ProxyPass in the vhost file that looks like this:
<VirtualHost *:80>
ProxyPreserveHost On
ServerName subdomain.domain.com
ProxyPass / http://localhost:9000/
ProxyPassReverse / http://localhost:9000/
Redirect / https://subdomain.domain.com/
</VirtualHost>
The SSL Certificate is issued by AWS.
This server is behind a AWS Load Balancer. From the load balancer I have 2 target groups. One is redirecting 80 to 80, and the other 443 to 443.
Right now the https://subdomain.domain.com is throwing 502 bad gateway error.
Could someone have any idea what the issue here might be? Thanks in advance!
Does this help: https://www.namecheap.com/support/knowledgebase/article.aspx/9821/38/redirect-to-https-on-apache?
It seems like you need to redirect permanent.
I've tried adding this to the vhosts file:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{subdomain.domain.com/}%{REQUEST_URI} [L,R=permanent]
as indicated in the aws documentation. It doesn't work, I get an error saying invalid redirect. No idea what the problem is.
Anyone else experienced this problem?

nginx or dns url rewrite or masking based on path

I work on one website which is travel blog and there is sub section mytravelsite.com/tickets which is whitelabel and everything under that mytravelsite.com/tickets/fares and other pages are pointing to another ip and this works fine.
But now i would like to switch and now main site to be mytravelsite.com which would be whitelabel from mytravelsite.com/tickets but without /tickets in url but still keep my blog so another trouble is that whitelabel don't have robots.txt so this i would have to serve too from my hosting.
So in the end i have hosting with 10.1.1.1 ip and whitelabel that resolve to 10.10.10.10 ip
What i need is:
everything under mytravelsite.com/blog to resolve to my hosting and my hosted website on 10.1.1.1
and also mytravelsite.com/robots.txt and mytravelsite.com/sitemap.xml to resolve to my hosting on 10.1.1.1
and everything else to resolve to the whitelabel at 10.10.10.10
i am guessing that this can be done either with some dns setup or nginx proxy or rewrite rules but everything i searched on internet for last 2 days ended up in failure.
DNS only considers the name, i.e. the part before the slash. You have always mytravelsite.com, so this can't be done purely in DNS.
I know this isn't a real/full answer.
I would try to solve it using proxy.
The included snippet is not a configuration of nginx but of an apache as I don't have similar setup for nginx within my reach now. But I believe it can be useful starting point though.
<VirtualHost 10.10.10.10:80>
ServerName mytravelsite.com
ProxyPreserveHost On
ProxyPass /blog/ http://10.1.1.1/ retry=1 timeout=600 keepalive=On
ProxyPassReverse /blog/ http://10.1.1.1/
ProxyPass /robots.txt http://10.1.1.1/ retry=1 timeout=600 keepalive=On
ProxyPassReverse /robots.txt http://10.1.1.1/
ProxyPass /sitemap.xml http://10.1.1.1/ retry=1 timeout=600 keepalive=On
ProxyPassReverse /sitemap.xml http://10.1.1.1/
</VirtualHost>
Notes:
10.*.*.* is a local-only network, so the 10.10.10.10 within the
virtualhost header is just for an illustration on what server this
definition should be put.
It also will not be working out of the box - just start here and
iterate to a final solution
You have not defined how could "your hosted website" be identified, therefore it is missing in the example

My website is showing apache test page

I created website on Amazon Web Server. I route my ip to my domain using ROUTE 53 service. but now my website is showing APACHE TEST PAGE rather then content while if i enter my ip address/wordpress it's working properly.
Any solution please?
maybe you forgot to add a virtual host in http.conf. Apache restart is needed after this.
<VirtualHost *:80>
DocumentRoot "/www/example2"
ServerName www.example.org
# Other directives here
</VirtualHost>
https://httpd.apache.org/docs/2.4/vhosts/examples.html

Apache Reverse Proxy to a Wordpress site passes subpath when it shouldn't

I've been trying to set up a reverse proxy on a main website to a blog site of the url format
example.com/blog -> blog.example.com
example.com/blog is on an Apache instance and in the httpd.conf I have added the following.
SSLProxyEngine on
ProxyPreserveHost Off
ProxyRequests Off
ProxyPassMatch /blog https://blog.example.com
ProxyPassReverse /blog https://blog.example.com
This all works but it keeps 404ing. The good news is it is actually reverse proxying correctly because it grabs the 404 page of the blog.
After looking at the apache access logs I found that it is passing the subpath for whatever reason /blog to blog.example.com so its fetching blog.example.com/blog. When users navigate to /blog, it does 404 naturally. However, my understanding was when setting up ProxyPassReverse is it would make the request at what was specified so in my above case it should be requesting blog.example.com and not passing the /blog at the end.
Here is the snippet from the documentation that confirms the above in how it should work:
For example, suppose the local server has address http://example.com/; then
ProxyPass /mirror/foo/ http://backend.example.com/
ProxyPassReverse /mirror/foo/ http://backend.example.com/
ProxyPassReverseCookieDomain backend.example.com public.example.com
ProxyPassReverseCookiePath / /mirror/foo/
will not only cause a local request for the http://example.com/mirror/foo/bar to be internally converted into a proxy request to http://backend.example.com/bar (the functionality which ProxyPass provides here).
Any ideas why this might be? Worst case I might try to add a redirect or a rewrite so /blog goes to the homepage but I do have my permalinks set up in such a way that the /blog is in the slug of articles.
FYI I am using Apache 2.2.
I'm an idiot. I was using ProxyPassMatch instead of ProxyPass. Ugh.

Apache2 Redirecting WWW to Naked Domain

My apache2 virtual host file for example.com is as below. I'm using this with wordpress site.
I set up the site without bothering to redirect the naked domain to www. When I try and add any code to rewrite the URL it redirects back to the naked domain (301 redirect) and I'm in a redirect loop.
I can't figure out why my stack is redirecting www to naked domain. Any help appreciated. Standard LAMP stack with wordpress.
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
</VirtualHost>
Also my DNS is set up with an A NAME for www pointing to the server IP address.

Resources