Subdomain not working on Apache/Linux - linux

I'm trying to set up a subdomain for on a client's web server. It's a CentOS server running Apache. So say the website is "example.com". I'm trying to create "bugs.example.com".
So far, I've added to the vhost.conf file the subdomain info:
<VirtualHost *:80>
ServerName bugs.example.com
ServerAlias bugs.example.com
DocumentRoot /var/www/www.bugs.example.com
<Directory "/var/www/www.bugs.example.com">
AllowOverride ALL
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I've added the server's IP address and the subdomain to /etc/hosts:
111.222.333.444 bugs.example.com
I've created the directory for the website files, and an index page at:
/var/www/www.bugs.example.com/index.html
Sadly, I still get a "Server not found" error when I go to bug.example.com. What am I missing here? The example.com domain name is registered through GoDaddy.com. Is there something that needs to be done there?

Related

VPS: xy.com working, but www.xy.com not

I set up a VPS for my project, but I can access it with myawesomeproject.com, but I got DNS error with www.myawesomeproject.com
My apache conf:
<VirtualHost *:80>
DocumentRoot /var/www/myawesomeproject/public
ServerName myawesomeproject.com
ServerAlias www.myawesomeproject.com
<Directory "/var/www/myawesomeproject/public/">
AllowOverride All
Options FollowSymLinks
</Directory>
ErrorLog /var/log/apache2/myawesomeproject-error_log
</VirtualHost>
I only have one DNS zone for it at the registrar:
Type - IP - TLS
A - 'MyVPS'sIP' - 3600
What's the problem?
The A Record is probably for your naked domain, so that's why the version without WWW is working.
You need to make an A record for the www subdomain pointing to the same IP as the naked domain, or create a CNAME record pointing to the naked domain.
Cheers

Apache Multi-project configuration

I have a server with an ip: XXX.XXX.XXX.XXX
In my server, i have several projects in the folder /var/www:
/var/www/project1
/var/www/project2/trunk/webroot
...
My 000-default.conf is like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Currently I access into them through the following url:
XXX.XXX.XXX.XXX/project1
XXX.XXX.XXX.XXX/project2/trunk/webroot
...
I have a domain that targets to my server
domain.com -> XXX.XXX.XXX.XXX
My intention is to create a subdomain for each project, and each subdomain points to the target folder of the project:
project1.domain.com -> XXX.XXX.XXX.XXX/project1
project2.domain.com -> XXX.XXX.XXX.XXX/project2/trunk/webroot
(I think the best solution will be that XXX.XXX.XXX.XXX/project2 targets directly to XXX.XXX.XXX.XXX/proyect2/trunk/webroot)
I have read that it will be great that each project has its own .conf file in apache, and enabling each site separately.
But I think that if I create a VirtualHost *:80 for each project (project1.conf, project2.conf) they will be in conflict and I dont know how to do it.
Can anybody help me?
Regards.
Virtual Host is the way to go... create one virtual host for each domain pointing to a folder on your server where to webpage is sotored.
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/example1"
ServerName www.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/example2"
ServerName www.example.org
</VirtualHost>
Etc... One VirtualHost for each domain / DocumentRoot convination
Soruce: https://httpd.apache.org/docs/current/vhosts/examples.html
##################### EDIT
I have tested it on my own server
Whithout touching the default.conf file I have created two new config files
root#raspberrypi:/etc/apache2/sites-available# pwd
/etc/apache2/sites-available
root#raspberrypi:/etc/apache2/sites-available#
Please ignore the default files I have not touched them I have just created two new files named project1.... and project2....
root#raspberrypi:/etc/apache2/sites-available# ls
000-default.conf project1_domain_com.conf
default-ssl.conf project2_domain_com.conf
root#raspberrypi:/etc/apache2/sites-available#
root#raspberrypi:/etc/apache2/sites-available# cat project*
<VirtualHost *:80>
DocumentRoot "/var/www/projects/project1/"
ServerName project1.domain.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/projects/project2/"
ServerName project2.domain.com
</VirtualHost>
root#raspberrypi:/etc/apache2/sites-available#
ENABLING SITES
root#raspberrypi:/etc/apache2/sites-available# a2ensite project1_domain_com.conf
Enabling site project1_domain_com.
To activate the new configuration, you need to run:
service apache2 reload
root#raspberrypi:/etc/apache2/sites-available# a2ensite project2_domain_com.conf
Enabling site project2_domain_com.
To activate the new configuration, you need to run:
service apache2 reload
root#raspberrypi:/etc/apache2/sites-available#
RELOAD APACHE
root#raspberrypi:/etc/apache2/sites-available# /etc/init.d/apache2 reload
[ ok ] Reloading apache2 configuration (via systemctl): apache2.service.
root#raspberrypi:/etc/apache2/sites-available#
################# SUBDOMAIN EDIT
For example I have a single server with an IP XXX.XXX.XXX.XXX that have multiple domains registered (15 domains now).
I have one virtual host entry for each domain that works this way:
domain1.example.com -> Load the domain1 web index.html page (without /nothing/else )
domain2.example.com -> Load the domain2 web index.html page hosted on another folder expecified on the second virtual host.
And finally ussing a2ensite or a2dissite I enable or disable the website as a web hosting provider do...
If for any reason you need that accessing the host domain3.something.com it redirects to domain3.something.com/something/diferent ... it should be done on your server ussing .htaccess file and its a entirely diferent question :D

Virtualhost Document Root changing web root for entire server

I currently have example.com pointing to Server one. I wanted to server example.com from a different directory ( /WebData )
I did this by editing httpd.conf
http://pastebin.com/UjHhRNTX
I this works as desired.
I then found out I needed to add website.org to the server. So I mounted another disk and created a dir called /WebDataWebsite
and created /etc/httpd/conf.d/websiteorg.conf with the following VHost:
http://pastebin.com/GTmqtABf
<VirtualHost *:80>
DocumentRoot "/WebDataWebsite"
ServerName website.org
ServerAlias www.website.org
<Directory "/WebDataWebsite">
Require all granted
</Directory>
</VirtualHost>
For some reason all traffic to example.com and website.org were both directed to index.htm in /WebDataWebsite
What I am doing wrong? How to I make /WebData (in httpd.conf) the default website but filter by servername website.org with the VHost?
You'll probably need to use Alias's for the second site. Have a look at http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias
It's unlikely that second declaration of the VH is being picked up by apache as it can not deal with two declarations of the same I believe.

Apache2 - Trouble Adding Subdomain

I have a Linode server running Ubuntu 11 and Apache2 and I'm trying to get a subdomain working. This is my mywebsite file in sites-available folder. I've tried putting the top part in its own file testing.mywebsite and reloading apache2 with no luck.
<VirtualHost *:80>
DocumentRoot /home/user2/www
ServerName testing.mywebsite.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin email#gmail.com
ServerName mywebsite.com
ServerAlias *.mywebsite.com
ServerAlias 192.155.90.135
#Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/user/public/mywebsite/www
#Log file locations
LogLevel warn
ErrorLog /home/user/public/mywebsite/log/error.log
CustomLog /home/user/public/mywebsite/log/access.log combined
</VirtualHost>
I have a website up and running and apache can find all the files in /home/user/public/mywebsite/www but when I go to the testing subdomain, my browser can't find it. I'm pretty unfamiliar with apache2, so any help is appreciated. Thanks.
Are your DNS records configured to point your computer at the desired hostname to your server's IP address when it resolves? Or, are you overriding with editing /etc/hosts?
I am somewhat unsure what "my browser can't find it" means, so please clarify if the above questions don't get you closer to your problem. It would be worth checking your log files for Apache in your specified paths and /var/log/apache2/.

Problems with Apache Virtual Hosts

I have recently just set up a RHEL based server running two domains. However, I am having difficulty hitting both domains from the browser. My config is:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName domainA.com
ServerAlias domainA.com *.domainA.com
DocumentRoot /home/domainA/public_html
<Directory "/home/domainA/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName domainB.com
ServerAlias domainB.com *.domainB.com
DocumentRoot /home/domainB/public_html
<Directory "/home/domainB/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
The problem is when I navigate to domainA.com I hit the correct Virtualhost (which is fine), however when I navigate to domainB.com it displays the Apache Test page.
Edit
I have a Firewall between the webserver and the web. I tested the rules governing Domain A and Domain B.
Domain A reaches target and a status 200 is returned.
Domain B reaches target and a status 403 (permission denied) is returned
What you need to do is take a look at sites-enabled and sites-available.
Here's the first entry when Googling: http://www.debian-administration.org/articles/412
Looks reasonable and should help you integrate that.
The problem is that you need separate entries for all the sites you want to run on this apache2. Simple entries in your config file don't do it. Only the first works, the rest is more or less ignored. Creating separate entries with sites-enabled and sites-available is the way to go here.

Resources