Apache2/Tomcat: Redirecting root url - apache

I have just moved my apache2/Tomcat9 server from windows to ubuntu.
ProxyPass and ProxyPassReverse are working fine. Known tomcat webapp urls are all passing through.
However, when I just enter the www.myservername.com it goes to the default var/www directory.
I tried redirecting using 000-default.conf. The following works for http://www.myservername.com but does not work for https://www.myservername.com
ServerName www.myservername.com
ServerName www.myservername.com
<VirtualHost *:*>
ServerName www.myservername.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Redirect permanent / https://www.myservername.com/ddd-college-website/entry
</VirtualHost>
So, in short, typing https://www.myservername.com/ into the browser, should take users to https://www.myservername.com/ddd-college-website/entry. But it's not happening
Any advice would be appreciated

Related

Why does Apache serve from /usr/local/apache2/htdocs and not /var/www/html?

In /etc/apache2/sites-enabled/000-default.conf I have the following config:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
</VirtualHost>
However, when I visit localhost, I get the "It works!" page, which is located in /usr/local/apache2/htdocs. (I've verified this by changing the file's contents and refreshing the page.)
Why is Apache serving from /usr/local/apache2/htdocs instead of /var/www/html as specified in the config?
Look for a symlink on either /var/www or /var/www/html.

Apache Virtual Hosts serves the vhost NOT matched

I set up an Apache Server with two Virtual Hosts and it has a very weird behaviour. I have a normal webserver, that should be server in all cases, except given the case, that the domain name is "biblio.name" or "biblio-intra.name", which should be redirected to a virtual machine located on my laptop, serving another webservice on Linux. On my laptop I use xampp for the Apache Server. I have the following "httpd-vhosts.conf" in my apache/conf/extra folder:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName sis.name/
ServerAlias *
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ProxyPass "/" "http://127.0.0.1:8080/"
ProxyPassReverse "/" "http://127.0.0.1:8080/"
ServerName biblio.name/
ServerAlias biblio-intra.name/
</VirtualHost>
So I expected it to redirect all requests to "biblio.name" and serve the rest as normal. However, it didn't!
When I enter my static ip-adress (assigned from the router) in the browser, I get served htdocs as normal, perfectly fine. When I enter biblio.name:8080 I also get normally served the virtual machine as expected (obviously, since 8080 automatically uses the redirect rule of the virtual machine.) However, when I type "sis.name" it redirects me to the virtual machine and when I type "biblio.name" it serves me from the htdocs.
I never experienced a behaviour like that and I don't get, why it serves the opposite host of the one supposed to.
Am I missing something?
For some reason I don't know (anymore), all my apache vhost configurations have the same value for ServerName and ServerAlias. Also the / in it seems odd. You can try listing biblio-intra.name as second option, but it should at first repeat the value from ServerName:
<VirtualHost *:80>
ServerName sis.name
ServerAlias sis.name
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>
<VirtualHost *:80>
ServerName biblio.name
ServerAlias biblio.name biblio-intra.name
ProxyPreserveHost On
ProxyRequests Off
ProxyPass "/" "http://127.0.0.1:8080/"
ProxyPassReverse "/" "http://127.0.0.1:8080/"
</VirtualHost>

How do I enable a site as a subdirectory of another site in Apache?

I'm trying to enable a service on my home server that has a different document root than my main site. I can't figure out how to edit the site .conf files so that I can run both the main site and the new service.
My use case: I've got a home server running Ubuntu 16.04.1 and Apache 2. I can browse to my site at ceres.local. I also installed OpenProject 6.1. After the install completes, I can browse to that service at ceres.local/openproject, but now browsing to ceres.local returns a 403 Forbidden.
I checked my sites-enabled, and I see that the 000-default.conf is no longer listed, just openproject.conf. So, I ran a2ensite 000-default.conf and service apache2 reload. Now, I can browse to ceres.local, but ceres.local/openproject returns a 404 Not Found.
How do I get both 'ceres.local' and 'ceres.local/openproject' to serve properly with the two .conf files below? Note the different document roots.
My 000-default.conf reads as follows:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ServerName ceres.local
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And my openproject.conf reads as follows:
Include /etc/openproject/addons/apache2/includes/server/*.conf
<VirtualHost *:80>
ServerName ceres.local
DocumentRoot /opt/openproject/public
ProxyRequests off
Include /etc/openproject/addons/apache2/includes/vhost/*.conf
ProxyPass /openproject/ http://127.0.0.1:6000/openproject/ retry=0
ProxyPassReverse /openproject/ http://127.0.0.1:6000/openproject/
</VirtualHost>
I know is a very old post.
But I spend 3 days to solve this and is a first post when we google
so, when you install openproject he create a file called openproject.conf and disable the 000-default.conf
inside this file are a configuration like this
Include /etc/openproject/addons/apache2/includes/server/*.conf
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /opt/openproject/public
ProxyRequests off
Include /etc/openproject/addons/apache2/includes/vhost/*.conf
# Can't use Location block since it would overshadow all the other
#Proxypass directives on CentOS
ProxyPass /help/ http://127.0.0.1:6000/help/ retry=0
ProxyPassReverse /help/ http://127.0.0.1:6000/help/
</VirtualHost>
but when you try acess the mydomain.com you receive the message 403 - forbitten
you just need modify the file like this
Include /etc/openproject/addons/apache2/includes/server/*.conf
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/html # <----- LOCATION WHERE YOU SITE ARE
#DocumentRoot /opt/openproject/public #<--- You Need comment this line
ProxyRequests off
Include /etc/openproject/addons/apache2/includes/vhost/*.conf
# Can't use Location block since it would overshadow all the other proxypass
directives on CentOS
ProxyPass /help/ http://127.0.0.1:6000/help/ retry=0
ProxyPassReverse /help/ http://127.0.0.1:6000/help/
So, if can see the proxypass below, apache will redirect to then when you put mydomain.com/help (you be redirect to openproject), mydomain.com (you main site )
I Hope with this help someone
Be Happy :)

Apache ServerAlias not redirecting to correct ServerName

i'm try to setup multiple wordpress sites on my Amazon EC2 instance. Here's how my httpd.conf file looks like:
<VirtualHost *:80>
ServerName www.domain1.com
ServerAlias domain1.com
DocumentRoot /var/www/html/domain1
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.co
ServerAlias domain2.co
DocumentRoot /var/www/html/domain2
</VirtualHost>
So, when i entered domain1.com or www.domain1.com in the browser, it redirects correctly to the content i wanted and so does www.domain2.co . However, when i entered domain2.co, it doesn't directs to the ServerName www.domain2.co but to the first VirtualHost settings www.domain1.com.
Anything i'm missing out here?
Try this. Apache will default to the 1st virtual host if it doesn't find a virtualhost match which means your second VirtualHost is being ignored. We use www. as an alias and the domain as the server name. See if this helps.
<VirtualHost *:80>
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /var/www/html/domain1
</VirtualHost>
<VirtualHost *:80>
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /var/www/html/domain2
</VirtualHost>
Figured it out guys, the browser caches previous data when domain2.co points to domain1.com. So even when i have set the virtualhost correctly for domain2.co, the browser will still load the previous cached data from domain1.com.
Solution will be to clear browser data.
Found out that another factor affecting this could be because of your ISP.
Read more here: https://sg.godaddy.com/help/what-factors-affect-dns-propagation-time-1746

New Virtual Host 301-redirects to old Virtual Host

I have an apache installed on Debian Linux. A virtual host, which is described in the file /etc/apache2/sites-enabled/site.conf, something like that
<VirtualHost *:80>
ServerName site.com
DocumentRoot /var/www/site
</VirtualHost>
I have added new Virtual Host to this file, so now this file looks like
<VirtualHost *:80>
ServerName site.com
DocumentRoot /var/www/site
</VirtualHost>
<VirtualHost *:80>
ServerName site-mirror.com
ServerAlias *.site-mirror.com
DocumentRoot /var/www/site
</VirtualHost>
and restarted apache
/etc/init.d/apache2 reload
Now, when I go to site-mirror.com, apache redirects me to site.com (301 redirect)
What could be the problem ?
I will appreciate any help, thanks
I think the redirection is done by wordpress to prevent SEO problems. you'll need some wordress specific module to support multi-domain access on the same wordpress installation like this one, domain-theme.
A very quick guess but the fact that both DocumentRoots are the same may be tricking apache and treating it as a redirect, try changing the mirror documentroot and see if you still get the 301.
Dave