I try to make two websites on the same IP. I have understand on my research that it is possible if i use domain and subdomains.
Right now i made this in my default config file for apache2 on ubuntu:
NameVirtualHost prem2.trixia.dk:80
NameVirtualHost srv6.trixia.dk:80
<VirtualHost prem2.trixia.dk:80>
ServerName prem2.trixia.dk
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost srv6.trixia.dk:80>
ServerName srv6.trixia.dk
ServerAdmin webmaster#localhost
DocumentRoot /var/www/host523.trixia.dk
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What i wonna do is, if you go to the website srv6.trixia.dk, it goes to the folder /var/www/host523.trixia.dk and if its prem2.trixia.dk, its just the default webpage.
Right now if i go to srv6.trixia.dk it goes to /var/www/html.
What have i done wrong?
I assume you use Apache 2.2 or lower, in 2.4 NameVirtualHost i deprecated.
It is recommended that you put an ip-address to NameVirtualHost with an optional port as argument, like this:
NameVirtualHost 123.123.123.123:80
On my server I have written it like this:
NameVirtualHost *:80
That says to Apache that it can have VirtualHosts on all of the servers ip-adresses. So replace your NameVirtualHost <servername>:80 with NameVirtualHost <ip-address>:80or NameVirtualHost *:80
Next I would rewrite your VirtualHost blocks to this:
<VirtualHost *>
ServerName prem2.trixia.dk
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *>
ServerName srv6.trixia.dk
ServerAdmin webmaster#localhost
DocumentRoot /var/www/host523.trixia.dk
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
that is, replace the <VirtuaHost>part of each of them.
I think the error you did was the two NameVirtualHostand that caused Apache to intepret your virtualhosts wrong.
This might be a good page for you to read also: http://httpd.apache.org/docs/2.2/vhosts/name-based.html
Related
On my AWS instance, I have the following setup
/var/www/html/admin <--- angularjs application
/var/www/html/api <--- angularjs application
/var/www/html/main <--- django application
How do I make them all accessible as "individual sites"? For example, browsing to:
http://ec2-xx-xx-xxx-xxx.eu-west-2.compute.amazonaws.com/admin
http://ec2-xx-xx-xxx-xxx.eu-west-2.compute.amazonaws.com/api
http://ec2-xx-xx-xxx-xxx.eu-west-2.compute.amazonaws.com/main
Should each be like going to a self contained site.
Right now going to http://ec2-xx-xx-xxx-xxx.eu-west-2.compute.amazonaws.com/main for instance (which is an AngularJS application), I see errors like this:
Failed to load resource: the server responded with a status of 404 (Not Found)
I logged onto the site and noticed that it thinks the assets live a directory above as opposed to in the "main" subdirectory. I can understand that I need to set up vhosts somehow... where do these go on an AWS instance and would they look like this?
<VirtualHost *:80>
ServerAdmin info#main.com
ServerName main.com
ServerAlias www.main.com
DocumentRoot /var/www/html/main
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin info#main.com
ServerName main.com/api
ServerAlias www.main.com/api
DocumentRoot /var/www/html/api
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin info#main.com
ServerName main.com/admin
ServerAlias www.main.com/admin
DocumentRoot /var/www/html/admin
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I have this conf-file set-up:
Listen 80
<VirtualHost 0.0.0.0:80>
ServerAdmin webmaster#localhost
ServerName test.example.com
WSGIScriptAlias / /var/django/test/test/wsgi.py
#WSGIPythonPath /var/django/test
<Directory /var/django/test/test>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost 0.0.0.0:80>
ServerAdmin webmaster#localhost
ServerName www.example.com
ServerAlias *.example.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Whenever I open www.example.com, test.example.com or example.com I always receive the standard apache website.
If I delete the second VirtualHost I get an access denied (since the permissions for the wsgi-file are note properly set).
But why can't I run 2 (or more) different VirtualHost of differnt subdomains?
Thanks!
Kev
PS.: I try to run a Django-Site on the subdomain test.example.com
I found the error.
In the second there was a "." instead of a "80".
Well, I'm pretty new to this, so, I'm sorry if I'm making some stupid mistake but I've been trying to make my Apache Virtual Hosts work fine for different domains. I have one VPS with CentOS 6 and Apache 2 where I'm running 2 websites with diffent domain names; they were both working fine some days ago. But After I made some changes (i dont remember them) they're acting stupidly. The problem is that the both of the domains are pointing to the first document root in the vhosts file. This is my vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin support#domain.me
DocumentRoot /var/www/domainme
ServerName domain.me
ErrorLog /var/www/log/domainme.log
</VirtualHost>
<VirtualHost *:80>
ServerAdmin support#domain.com
DocumentRoot /var/www/domaincom
ServerName domain.com
ErrorLog /var/www/log/domaincom.log
</VirtualHost>
Everytime I try to access domain.com it gives me the index file of domain.me but if I put domain.com's configuration before the domain.me in vhosts file, and go to domain.me; it will give me the index of domain.com. I have two IP's for the VPS by the way.
Thank for reading, hope that its not a big issue.
Try this one
Listen *:80
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin contact#domain.tld
DocumentRoot /path/to/domain1/
ServerName domain1.com
ServerAlias domain1.com www.domain1.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin contact#domain.tld
DocumentRoot /path/to/domain2/
ServerName domain2.com
ServerAlias domain2.com www.domain2.com
</VirtualHost>
I'm trying to set up some basic virtualhosts in Apache2, within the domain
nosoftpatents.com (invented). I'm supposed to have two subdomains, friendly
and previous, each of them accessible from two ports, 80 and 8800, that are to
be linked to the stable and devel subdirectories of each domain. So far, I
have this:
<VirtualHost *:80>
ServerName friendly.nosoftpatents.com
DocumentRoot /var/www/nopatents/friendly/stable
</VirtualHost>
<VirtualHost *:80>
ServerName previous.nosoftpatents.com
DocumentRoot /var/www/nopatents/previous/stable
</VirtualHost>
<VirtualHost *:8800>
ServerName friendly.nosoftpatents.com
DocumentRoot /var/www/nopatents/friendly/devel
</VirtualHost>
<VirtualHost *:8800>
ServerName previous.nosoftpatents.com
DocumentRoot /var/www/nopatents/previous/devel
</VirtualHost>
Is there a more elegant way of doing it? Some way of grouping the hosts from the
same port?
I am trying to route requests to different docroots depending on the HOST name (not domain name):
<VirtualHost 123.123.12.12:80>
SuexecUserGroup "#521" "#521"
ServerName forum.somesite.net
DocumentRoot /home/somesite/public_html/forums
</VirtualHost>
<VirtualHost 123.123.12.12:80>
SuexecUserGroup "#521" "#521"
ServerName www.somesite.net
DocumentRoot /home/somesite/public_html
</VirtualHost>
It is not working though. Apache seems to go to the first entry regardless of what is in the hostname. What am I doing wrong?
Try changing the second Virtual host to this
<VirtualHost 123.123.12.12:80>
SuexecUserGroup "#521" "#521"
ServerName somesite.net
ServerAlias www.somesite.net
DocumentRoot /home/somesite/public_html
</VirtualHost>