Apache Virtual Host (Ubuntu) redirecting to wrong document root - apache

I'm trying to setup an Apache server with several virtual hosts (www.domain.com & store.domain.com), but for some reason, when I just have one of them enabled (store.domain.com) Apache redirects to the wrong document root (/var/www), which is apparently the default one. This is the virtual host configuration file for the one that's not redirecting correctly:
<VirtualHost *:80>
ServerName store.domain.com
ServerAdmin mail#domain.com
DocumentRoot /var/www/store/public_html/
ErrorLog /var/www/store/logs/error.log
CustomLog /var/www/store/logs/access.log combined
</VirtualHost>
When I run the command apache2ctl -S I get the following:
Name or service not known: AH00547: Could not resolve host name *80 --ignoring!
AH00558: apache2: Could not reliably determine the server's fully qualified domain name,
using xxx.xxx.xxx.xxx. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
....
Looks like the key is on the first line of the previous error, but I can't figure out what's wrong.
When I have the following virtual host enabled, it works fine:
<VirtualHost *:80>
ServerAdmin mail#domain.com
ServerName www.domain.com
DocumentRoot /var/www/html/www/public_html/
ErrorLog /var/www/html/www/logs/error.log
CustomLog /var/www/html/www/logs/access.log combined
</VirtualHost>
When this last virtual host is enabled, store.domain.com redirects to www.domain.com

Related

Reverse Proxy not running on HTTPS Apache Server

Created a Hello_World NodeJS App.
The app is accessible at http://<DOMAIN_NAME>/app & http://<DOMAIN_NAME>:3000
but when accessed via https://<DOMAIN_NAME>/app it returns an error.
http://<SERVER_IP>:3000 also works & https:<SERVER_IP>:3000 returns an error
sudo apachectl -S
OUTPUT :
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80 okoyama.in (/etc/apache2/sites-enabled/okoyama.in.conf:1)
*:443 okoyama.in (/etc/apache2/sites-enabled/okoyama.in.conf:45)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
<VirtualHost *:80>
ServerAdmin admin#okoyama.in
ServerName okoyama.in
ServerAlias www.okoyama.in
DocumentRoot /var/www/okoyama.in/public_html
ProxyPreserveHost On
ProxyPass /app http://localhost:3000/
ProxyPassReverse /app http://localhost:3000/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot /var/www/okoyama.in/public_html
ServerName okoyama.in
SSLEngine on
SSLCertificateFile /etc/ssl_install/certificate.crt
SSLCertificateKeyFile /etc/ssl_install/private.key
SSLCertificateChainFile /etc/ssl_install/ca_bundle.crt
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
</IfModule>
The above code has Reverse Proxy enabled for HTTP. HTTPS works normally. I have removed the Reverse Proxy section from 443 Port for now to make the working code cleaner.
Multiple variations of solutions suggested on various platforms have been tried in Port 443 section but none worked until now.
The included turning on SSLProxyEngine & a similar Proxy method as mentioned in the HTTP section.
Suggest possible solution. I will retry & post for clarity.

trying to configure my virtual host files on an apache server for local development on a mac

trying to configure a virtual host for my project however the server automatically picks up the root directory. Below is what i have configured it to be.
<VirtualHost 127.0.0.2:8080> ServerName project-1.local DocumentRoot "/Users/mac/Projects/project-1/public" <Directory "/Users/mac/Projects/project-1/public"> AllowOverride All Require all granted </Directory> </VirtualHost>
However this is what i get when i run apachectl -S
VirtualHost configuration: 127.0.0.2:8080 project-1.local (/usr/local/etc/httpd/extra/httpd-vhosts.conf:40) ServerRoot: "/usr/local/opt/httpd" Main DocumentRoot: "/usr/local/var/www" Main ErrorLog: "/usr/local/var/log/httpd/error_log" Mutex mpm-accept: using_defaults Mutex default: dir="/usr/local/var/run/httpd/" mechanism=default PidFile: "/usr/local/var/run/httpd/httpd.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="_www" id=70 not_used Group: name="_www" id=70 not_used
What am i doing wrong here?
this is what my hosts file looks like
127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 127.0.0.2 project-1.local
i tried changing the vhost file and resaving it however it didnt work

apache mod_jk | Virtualhost does not listen the doimain name to forward the request to Tomcats

Now I have another problem on my work. I have adjusted the configuration so that now, depending on the URL, the request should be forwarded to the 3 tomcats in the backend.
If the URL is www.mysite.com, the request should be forwarded to Tomcat 1, and so on.
Of course, they're dummy websites in virtualhost, or at least that's what my server should think so. However, it doesn't work that way. If I go to mysite.com, as expected, mysite.com is actually called instead of the request being forwarded to Tomcat 1.
When I call up localhost, the Tomcat start page is displayed directly, which should actually be displayed for localhost:8181. The Apache start page should actually appear. The Tomcats can be reached at /app1..3. So that's not the problem.
The question is: what and where exactly do I have to change in order to achieve my goal?
httpd.conf
Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.mysite.com
RewriteEngine on
RewriteRule ^/(.*)$/app1/$1 [l,PT]
JkMount /* tomcat1
</VirtualHost>
<VirtualHost *:80>
ServerName www.test.de
RewriteEngine on
RewriteRule ^/(.*)$/app2/$1 [l,PT]
JkMount /* tomcat2
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.de
RewriteEngine on
RewriteRule ^/(.*)$/app3/$1 [l,PT]
JkMount /* tomcat3
</VirtualHost>
output of "httpd -S"
AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf/httpd.conf:48
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80 is a NameVirtualHost
default server www.mysite.com (/etc/httpd/conf/httpd.conf:50)
port 80 namevhost www.mysite.com (/etc/httpd/conf/httpd.conf:50)
port 80 namevhost www.test.de (/etc/httpd/conf/httpd.conf:57)
port 80 namevhost www.example.de (/etc/httpd/conf/httpd.conf:64)
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex lua-ivm-shm: using_defaults
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex default: dir="/etc/httpd/run/" mechanism=default
Mutex cache-socache: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex watchdog-callback: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
PidFile: "/etc/httpd/run/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48
[Your RewriteRules are missing a space between the pattern and the substitution.]
It is usually a bad idea to rewrite URI paths that will be sent to Tomcat: servlet applications commonly generate URIs using
<scheme>://<serverName>:<serverPort>/<contextPath>/relative/path/to/resource
While the AJP protocol provides Tomcat with the correct values of <scheme>, <serverName> and <serverPort>, the original value of <contextPath> received by the Apache HTTP Server is never forwarded to Tomcat.
So, e.g.:
a client requests http://example.com/index.html,
your rewrite rule changes it to http://example.com/app1/index.html and sends it to Tomcat,
Tomcat generates a HTML page with an image located at http://example.com/app1/image.png,
the client requests http://example.com/app1/image.png
your rewrite rule changes it to http://example.com/app1/app1/image.png, which does not exist.
An easy solution is to deploy your application under the same context path under which they will be seen by the clients: rename all applications as ROOT to deploy them at the root of your website.

virtual host setup shows default apache2 page

I have setup a new virtual host on my ubuntu 16.04 machine but it redirects me to apache's default virtual host (which is disabled).
Below is the contents of the apache virtual hosts config file;
VirtualHost configuration:
*:80 roomba.dev (/etc/apache2/sites-enabled/roomba.dev.conf:2)
*:443 is a NameVirtualHost
default server roomba.dev (/etc/apache2/sites-enabled/default-ssl.conf:2)
port 443 namevhost roomba.dev (/etc/apache2/sites-enabled/default-ssl.conf:2)
port 443 namevhost roomba.dev (/etc/apache2/sites-enabled/roomba.dev.conf:10)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
the domain is https://roomba.dev
You do not really have a question but based on the fact that I too am trying to setup a virtual host if not several, I have found a work around for the official Ubuntu virthost setup tutorial and the associated docs . They just do not work, see these comments and the confusion that ensued. I am assuming the were providing a clean way to add virtualhosts, similar to how you add APT lists in Linux.
Define your new virtual host in the default-ssl.conf file:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
...
</VirtualHost>
</IfModule>
I hope that you did not delete it. After that first virtual host closing tag, add a new host as described in the tutorial instead of creating a new configuration file. For example;
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
...
</VirtualHost>
<VirtualHost *:80>
#ServerAdmin admin#roomba.dev
DocumentRoot /path/to/new/virtualhost
ServerName roomba.dev
ErrorLog ${APACHE_LOG_DIR}/roomba-error.log
CustomLog ${APACHE_LOG_DIR}/roomba-access.log combined
</VirtualHost>
</IfModule>
You can add as many as you want. I am still searching for documentation that could discourage this with explanations. As again, the Apache tutorial does not work but this does, yet they bothered to write it that way, several times. There must be a reason why.
NB: do not touch any permissions. Except the original virtual server directories, based on the http error codes.

Why doesn't this Apache virtualhost entry work?

I'm running Apache 2.4.6 on Ubuntu 13.
In sites-available, I have a conf file for my site that contains only this:
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin somebody#somewhere.com
ServerName www.ourco.me
ServerAlias ourco.me
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/ouruser/public/ourco.me/public
# Log file locations
LogLevel warn
ErrorLog /home/ouruser/public/ourco.me/log/error.log
CustomLog /home/ouruser/public/ourco.me/log/access.log combined
</VirtualHost>
There are no other conf files enabled. When I have use apachectl -S to display the sites, it shows:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
port 80 namevhost www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
alias ourco.me
port 80 namevhost www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
alias ourco.me
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
The first thing I notice is the duplicate entry for namevhost www.ourco.me. And when I visit the site in a browser, I get:
You don't have permission to access / on this server.
Apache/2.4.6 (Ubuntu) Server at www.ourco.me Port 80
All the directories and files specified in the conf file exist. a2ensite and a2dissite work as expected to add/remove a symlink for this file from sites-enabled, so it's looking at the right file. Does anyone know why its directives are being ignored? Thanks.
Put Allow from all
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin somebody#somewhere.com
ServerName www.ourco.me
ServerAlias ourco.me
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/ouruser/public/ourco.me/public
# Log file locations
LogLevel warn
ErrorLog /home/ouruser/public/ourco.me/log/error.log
CustomLog /home/ouruser/public/ourco.me/log/access.log combined
Allow from all
</VirtualHost>
This appears to solve the problem:
<Directory />
Require all granted
</Directory>
when placed in the VirtualHost entry.
That snippet came from this post. I'm looking at this Apache doc to see why it works.