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>
Related
I followed this tutorial to get Vhosts working on my website. https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04-quickstart. For my second site at reporting.mydev.site, my website still redirects to my main website at mydev.site. I am using Apache as my HTTP server, here are my two .conf files for my main server and my new Vhost.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName mydev.site
DocumentRoot /var/www/mydev.site/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www>
AllowOverride All
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =mydev.site
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
And here is the .conf file for the vhost I cannot get to work
<VirtualHost *:80>
ServerName reporting.mydev.site
ServerAdmin webmaster#localhost
DocumentRoot /var/www/reporting.mydev.site/public_html
ServerAlias www.reporting.mydev.site
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I found the problem, the issue was that I needed to create the https version of this file using certbot "reporting.mydev.site-le-ssl.conf". my second vhost was pointing to the first only for the https version but for the http only version it was correctly pointing to my new website.
Is it possible in the apache config file to use regular expressions in the ServerName and ServerAlias field to have 2 domains use the exact same config file vs. creating 2 for each domain. I was trying something like this, but was getting an error from Apache:
<VirtualHost *:80>
ServerAdmin admin#test.com
ServerName [test.com|test.net]
ServerAlias [www.test.com|www.test.net]
DocumentRoot /var/www/test.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I use a Ubuntu 16.04 server VM on which I have to configure the following domains:
maindomain.com:80
otherport.com:8080
Each domain pointing to the VM's IP, but to a different directory obviously.
I managed to get bind9 to make these domains point to the VM's IP when the VM is the DNS server, and I configured Apache to get the following results:
Good:
maindomain.com:80 returns maindomain's index
otherport.com:8080 returns otherport's index
Bad:
maindomain.com:8080 returns otherport's index
otherport.com:80 returns maindomain's index
If I put both on port 80, each is separated, but if I do different ports it seems that Apache just cares about the port.
How could I block the access to maindomain.com:8080 and otherport.com:80?
maindomain.com.conf file:
<VirtualHost maindomain.com:80>
ServerAdmin webmaster#localhost
ServerName maindomain.com
ServerAlias www.maindomain.com maindomain.com
DocumentRoot "/var/www/html/maindomain"
<Directory /var/www/html/maindomain>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
otherport.com.conf file:
<VirtualHost otherport.com:80>
ServerAdmin webmaster#localhost
ServerName otherport.com
ServerAlias www.otherport.com otherport.com
DocumentRoot "/var/www/html/otherport"
<Directory /var/www/html/otherport>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I managed to get it done, but I think it's more of a dirty hack than an actual solution. I made two more virtual hosts like so :
maindomain.com.trap.conf
<VirtualHost *:8080>
ServerAdmin webmaster#localhost
ServerName maindomain.com
ServerAlias www.maindomain.com maindomain.com
DocumentRoot "/var/www/html/maindomain"
<Directory /var/www/html/maindomain>
Require all denied
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The other one having the names and port switched.
By the way, I left <VirtualHost *:80> and <VirtualHost *:8080> in the first two .conf files I mentioned in my first post.
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>
I have two url domain, abc.com and xyz.com. Both domain were setted to go to same ec2 instance at Amazon. I have two php application on this server, one deployed at /var/www/html and the other one at /var/www/html/xyz.
My issue is how change the httpd.conf config file to redirect all user that access by abc.com to the root site and all traffic by xyz.com go to /var/www/html/xyz
I tried do it adding the following code.
<VirtualHost xyz.com.br:80>
ServerAdmin email#gmail.com
DocumentRoot "/var/www/html/xyz"
ServerName xyz.com.br
Errorlog "logs/error_log"
CustomLog "logs/access_log" common
Alias /wedding "/var/www/html/xyz"
</VirtualHost>
<VirtualHost abc.com.br:80>
ServerAdmin email#gmail.com
DocumentRoot "/var/www/html"
ServerName abc.com.br
Errorlog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
Well, after some trial and error, I finally got it.
First I put each site inside a subfolder of /var/www/html.
/var/www/html/abc
/var/www/html/xyz
At my httpd.conf I add the following code
<VirtualHost *:80>
ServerAdmin email#gmail.com
DocumentRoot "/var/www/html/xyz"
ServerName xyz.com
ServerAlias www.xyz.com
Errorlog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin email#gmail.com
DocumentRoot "/var/www/html/abc"
ServerName abc.com
ServerAlias www.abc.com
Errorlog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
#DocumentRoot "/var/www/html"
For each wordpress settings I changed the wordpress url and site url to the respective domain url and "VoilĂ ", it's working!