I am trying to add domain and subdomain in apache virtual host. I already created the subdomain and pointed to my type A record. I dont see any issues over there.
Below is my httpd.conf entry: now only my root domain i am able to access, subdomain I could not access, I have gone through many links, but nothing worked for me.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot "/var/www/html"
</VirtualHost>
<VirtualHost *:80>
ServerName admin.mydomain.com
DocumentRoot "/var/www/admin"
</VirtualHost>
Can someone help me on this please ?
Related
I'm trying to make it so when someone visits my site at sub.example.com, it sends them to a different folder than someone who visits example.com. Simple, yes? This is the code I use to do it:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/sub"
ServerName sub.example.com
ServerAlias sub.example.com
</VirtualHost>
I have the DNS for my domain set for a wildcard so that any subdomain still directs to my server.
The problem is, now whenever someone visits example.com or sub.example.com or any subdomain, it shows the content from /htdocs/sub
I only want it to show /htdocs/sub when sub.example.com is visited, how do I do that?
From what I've read my execution seems right, but maybe I've missed one thing that causes this to happen? I've reinstalled xampp to no avail
My main httpd.conf has this line ServerName example.com:80 if this helps
I ended up finding a solution, and to anyone in the future with the same problem, this is what I did:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot "C:/xampp/htdocs/"
</VirtualHost>
<VirtualHost *:80>
ServerName sub.example.com
DocumentRoot "C:/xampp/htdocs/sub"
</VirtualHost>
I assume that basically for the VirtualHost to differentiate between sub.example.com and example.com then a VirtualHost first must be defined for example.com before any subdomains can be configured
I need all url mydomain.com, a.mydomain.com, b.mydomain.com, whatever.mydomain.com....
point to the same DocumentRoot, the subdomain is dynamic(maybe have more than hundreds)
Now I have the following lines in 000-default.conf:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias *.mydomain.com
The mydomain.com is work, but all subdomain is not found.
Can someone help me? thanks so much.....
For example:
A user register a new account, the new account is "obama" then the url would be "obama.mydoamin.com". The subdomain can be entry when the account create immediately.
Wildcard sub-domains are possible using Apache virtual hosts.
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/app1
ServerName xyz1.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/example
ServerName example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/wildcard
ServerName other.example.com
ServerAlias *.example.com
</VirtualHost>
The first entry will become the default if you don't get an explicit match. So if you had xyz.otherexample.com point to it, it would be caught be xyz1.example.com. You need to turn on the name based virtual hosts with the first entry.
For further details you can also refers to apache documentation apache Doc
My goal is to have the following occur, when the user visits the sites below to the left it takes them to the directories on the right:
www.example.com or example.com => /var/www/example/public_html/
*.example.com => /var/www/example/public_html/sites/%1/public_html/
I have tried the following:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/public_html
</VirtualHost>
<VirtualHost *:80>
ServerAlias *.example.com
VirtualDocumentRoot /var/www/example/public_html/sites/%1/public_html
</VirtualHost>
The main domain works with or without www, but every time I try to visit any other subdomain it takes me to and gives me a 500 Internal Server Error. The URL changes to look like below when I type in a subdomain:
{subdomain}.example.com/sites/{subdomain}/public_html/
I am on Apache 2.4.7 and yes I have setup the WildCard on my DNS server. I would greatly appreciate any answers deeming that I have been slamming my head on a wall for 2 weeks trying to get this working.
Okay the whole problem was from the wildcard directory being beneath another directory that is already bound. After I made a directory elsewhere it started working like expected, go figure...
Hope this helps anyone else who happens to run into this odd bug... ^_^
I think the configuration you are looking for it's quite similar to this one:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/public_html
</VirtualHost>
<VirtualHost *:80>
ServerName *.example.com
ServerAlias *.example.com
DocumentRoot /var/www/wildcardexample/public_html
</VirtualHost>
What to you think?
In this case, any subdomain will be redirected to the same site. Is this the configuration you want? Or you want different configurations for each subdomain?
I'm having some issue with setting/adding sub domains.. to my apache2(httpd)..
I have this in my httpd.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin stitofte#homiecraft.pro
DocumentRoot /var/www/html/HomieCraft
ServerName www.homiecraft.pro
ServerAlias homiecraft.pro
</VirtualHost>
<VirtualHost *:80>
ServerName stats.homiecraft.pro
ServerAlias www.stats.homiecraft.pro
ServerAdmin stitofte#homiecraft.pro
DocumentRoot /var/www/html/stats
</VirtualHost>
homiecraft.pro works just fine...
but stats.homiecraft.pro doesn't work at all.... I have made a DNS a record.. And made "stats" point to the listening address... But still it doesn't work...
Any help would be nice... I have had this setup before... But for some reason i can't get it to work this time...
In Apache2 the Virtual Hosts must be add in ../apache2/conf/httpd-vhosts.conf File instead of main configuration file i.e ../apache2/conf/httpd.conf
then reboot the apache2 servie i.e ../apache2/bin/apa[tab] -k restart.
Now It will work fine.
Normally the problem is in the Dns record, check the subdomain add at dns record and check the type, which is sets CNAME and the main domain the type is A.
And check too the ip direction the subdomain
Change the serverAlias at subdomains quit the www.
This has probably been asked but I can't find a straight answer, or the ones I found don't work.
I have one domain mydomain.com, resolving to an IP; let's call it 8.8.8.8. The DNS settings also point two subdomains to that IP address with an A record. These are dev.mydomain.com and staging.mydomain.com. Both have an A-record pointing to 8.8.8.8.
On the server (8.8.8.8) I have two virtual hosts files. These are as follows:
staging.mydomain.com.conf
<VirtualHost *:80>
ServerName staging.mydomain.com
DocumentRoot /var/www/html/mydomain.com/staging/
</VirtualHost>
And...
dev.mydomain.com.conf
<VirtualHost *:80>
ServerName dev.mydomain.com
DocumentRoot /var/www/html/mydomain.com/dev/
</VirtualHost>
The problem is:
Regardless of whether I visit http://staging.mydomain.com or http://dev.mydomain.com, I always land on staging.mydomain.com (Apache serves these files).
I have restarted Apache and even the server. If I change the order of the .conf files so that dev is first, I always see that. Any suggestions would be so appreciated. Thanks!
update
I find myself back at this problem again! If you know that your syntax is correct, you might have a bad symlink. Delete it and recreate again, restarting apache in-between. I just did this and it solved hours of head-scratching. On CentOS you can check your available vhosts with httpd -S
update 2
I've also found this issue to exist when the apache log files for the virtual host don't exist, or aren't writable.
Sounds like you need to add NameVirtualHost directive to your configuration.
NameVirtualHost *:80
Under some circumstances Apache may not be able to handle *:80 VirtualHosts correctly. In those cases you should map VirtualHosts directly on specific IPs.
NameVirtualHost 8.8.8.8:80
<VirtualHost 8.8.8.8:80>
ServerName staging.mydomain.com
ServerAlias stage.mydomain.com
DocumentRoot /var/www/html/mydomain.com/staging/
</VirtualHost>
<VirtualHost 8.8.8.8:80>
ServerName dev.mydomain.com
ServerAlias development.mydomain.com
DocumentRoot /var/www/html/mydomain.com/dev/
</VirtualHost>
You can also run apachectl -t -D DUMP_VHOSTS to see how Apache parses the VirtualHost configuration.
Update: As mentioned in the comments, usually you can just use NameVirtualHost *:80. So most of the time you can configure the virtual hosts as follows.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName staging.mydomain.com
ServerAlias stage.mydomain.com
DocumentRoot /var/www/html/mydomain.com/staging/
</VirtualHost>
<VirtualHost *:80>
ServerName dev.mydomain.com
ServerAlias development.mydomain.com
DocumentRoot /var/www/html/mydomain.com/dev/
</VirtualHost>