Apache VirtualHost not pointing to correct subdirectory - apache

I am a newbie to apache and server setup. I am migrating several sites from GoDaddy to a DigitalOcean VPS droplet. I am moving my first site over (a Wordpress install) and am having some trouble with VirtualHost. Here is the configs:
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/html/domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Heres the thing, I have a www alias set up in the domain name records, and www.domain.com points correctly to the site, but domain.com points to the root var/www/html, not the subdirectory where the site is. I've searched for far too long, but every tutorial and forum seems to provide the same code I currently have configured. What am I doing wrong? I want to make sure it all works correctly before I take the next step of installing an SSL, but I am spinning my wheels at the moment.

The correct way to set up a virtual host is:
<VirtualHost *:80>
ServerAdmin admin#domain.com
DocumentRoot /path/to/the/directory
DirectoryIndex index.html index.php
ServerName domain.com
ServerAlias www.domain.com
ErrorLog ${APACHE_LOG_DIR}/domain.com.error.log
CustomLog ${APACHE_LOG_DIR}/domain.com.access.log combined
<Directory /path/to/the/directory>
Options -Indexes
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Related

Apache Dynamic VirtualHost routing not working

I have a Codeigniter project that i want to access on main domain e.g domain.com and on multiple dynamic subdomains. The project files are at /var/www/ Directory. Each of the sub-directories are being accessed via "SubdirectoryName.domain.com".
I am using virtual hosts configuration and my main domain is working fine with all its routing but on subdomains, main page is working but routing and htaccess is not working. If i add/index.php in url it works but due to htaccess not working im not able to remove it from url.
I have tried this virtualhost configuration but it doesn't seem to work
This is my virtualhost conf file code
<VirtualHost *:80>
ServerName domain.co.uk
ServerAlias www.domain.co.uk
ServerAdmin webmaster#testing.com
DocumentRoot /var/www/domain.co.uk/public_html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/domain.co.uk/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName domain.co.uk
ServerAlias *.domain.co.uk
ServerAdmin webmaster#testing.com
VirtualDocumentRoot /var/www/%1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Installed SSL on Apache server, page not responding

My question is about SSL installation. I purchased a new SSL for a website that's hosted on a Ubuntu 16.04 box with Apache 2.4.29. I was able to get this installed and I'm not getting any errors but my page is not redirecting. I've followed some guides (DigitalOcean) but feel as I'm missing something.
I have checked the sites-available files (000-default.conf, default-ssl.conf & example.com.conf) and I'm not seeing anything that's catching my eye, but I feel I migtht be missing something. I've checked the status of Apache and I'm not getting any errors and I've restarted the services several times to no avail.
Here's a general breakdown of what I have. Am I missing something? Is additional information required for setting this up?
000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
Redirect "/" "https://example.com/"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
default-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
SSLCertificateFile /root/example.com.crt
SSLCertificateKeyFile /root/www.example.com.key
SSLCACertificateFile /root/intermediate.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>4
mydomain.com.conf
<VirtualHost *:443>
ServerAdmin admin#somedomain.com
ServerName mydomain.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/html
Redirect permanent / https://example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Here is my attempt at a combined configuration. Note that I do not have your setup to test it, but I have used similar configurations on production servers.
First define your port 80 VirtualHost (000-default.conf in your setup):
Listen 80
<VirtualHost *:80>
Redirect "/" "https://example.com/"
LogLevel debug
ErrorLog "${APACHE_LOG_DIR}/80_error.log"
CustomLog "${APACHE_LOG_DIR}/80_access.log" combined
</VirtualHost>
No need for a DocumentRoot since you redirect everything.
Then comment out default-ssl.conf. This file is an example of what you could do to setup an SSL enabled VirtualHost. If you use that file AND another VirtualHost on port 443, this one will always be used, since Apache uses the first VirtualHost it finds that matches the client's request (here port 443).
Another point, VirtualHost are not "added" to one another. Each is independent of the others and must contain a complete configuration. This means you cannot put some configuration in on VirtualHost on port 443, and some in another and expect it to work.
Then create your example.com.conf file:
Listen 443
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin admin#example.com
SSLCertificateFile "/root/example.com.crt"
SSLCertificateKeyFile "/root/example.com.key"
SSLCACertificateFile "/root/intermediate.crt"
LogLevel debug
ErrorLog "logs/443_error_log"
CustomLog "logs/443_access_log" combined
DocumentRoot "/var/www/example.com/html"
DirectoryIndex index.html
<Directory "/var/www/example.com/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
Some notes:
I put the LogLevel at debug, so you can troubleshoot, but once it is working, change it to error. Otherwise you will have huge log files quickly!
For the same reason, I split the logs for port 80 and port 443. Each VirtualHost should have its own logs.
The certificate files must match the domain name. Not the filename (although it makes it easier to match), but the certificate itself.
If you want your certificate to cover example.com and www.example.com, both names must be added to the alternate names in the certificate.
I do not understand why you have Redirect permanent / https://example.com in your configuration. You are already in the https, port 443 VirtualHost.
The options based on <FilesMatch> directives in the default ssl configuration can be added if you want.
This setup will ensure that all http requests will be redirected to https://example.com. Then it will use the :443 VirtualHost, use the proper certificate for that domain and serve the content from the DocumentRoot directory.

joomla admin in subdomain blank page

I am having trouble accessing the Joomla administrator page in a subdomain.
Here's what it's like, the site is http://test.com and the admin page must be http://admin.test.com
I am using a WAMP server with virtual host enabled.
here's my httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin admin#test.com
DocumentRoot "c:\wamp\www\test"
ServerName test.com
ServerAlias www.test.com
ErrorLog "C:\wamp\www\test\logs\error.log"
CustomLog "C:\wamp\www\test\logs\access.log" common
<Directory "c:/wamp/www/test">
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#test.com
DocumentRoot "C:\wamp\www\test\administrator"
ServerName admin.test.com
ServerAlias www.admin.test.com
ErrorLog "C:\wamp\www\test\logs\error.log"
CustomLog "C:\wamp\www\test\logs\access.log" common
<Directory "c:/wamp/www/test/administrator">
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
test.com works fine, but the admin doesn't. It only displays a white blank page. I also noticed that the redirection works in admin since the page title loads the admin page title.
I'm using Joomla! 3.4.4 Stable, and WAMP Server with Apache/2.4.9 and PHP 5.5.12.
In your configuration.php file under your Joomla website, set $error_reporting to "maximum". This will show you what the error really is and will give you pinpoints on how to fix it.

drupal and wordpress together on one server

I have two domains:
example1.com - is a drupal site.
example2.com - is a wordpress multisite.
Both domains live on the same physical host. I am using Ubuntu 14.04 and Virtualhosts.
Everytime I enable example1.com when I navigate to example2.com (or any domain in my multisite) I get the drupal install page. I should be seeing example 2's index page. Can anyone help? Here are the vhost.conf files
example1 vhost.conf
<VirtualHost *:80>
ServerName example1.com
ServerAlias *.example1.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/example1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
example2.conf
<VirtualHost *:80>
ServerName example2.com
ServerAlias *.example2.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/example2.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
When I disable example1.conf everything with the wordpress multisite (example2.conf) works as expected...
When I try to specify a domain name on the virtualhost (like
I get an 500 error.
Can anybody point me in the right direction?
It looks like there was a two part problem here. I hadn't properly closed a tag
in my .htaccess file for site example2.
When I removed this, I would get the drupal install page for example1 and example2. What I wound up doing to resolve this issue was to move both virtualhosts into one .conf file in Ubuntu.... for whatever reason that seemed to resolve the issue.

Subdomain returns cgi error

I have created a virtual host with a subdomain, the subdomain's dns is pointed at the server. When I visit the subdomain I get the following error:
The requested URL "/cgi-sys/defaultwebpage.cgi" was not found on this server.
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
ServerAlias test.domain.com
ServerAdmin admin#domain.com
DocumentRoot /var/www/public/domain.com
<Directory "/var/www/public/domain.com">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /error.log
CustomLog /access.log combined
</VirtualHost>
I have tried using *.domain.com as well.
If I use a local host to point domain.com at the server it works as expected, but using localhost does not allow the subdomain to work in either case.
Turns out that my syntax is correct, chrome's dns caching had cached the bad page. Using firefox worked.