I have set up one conf file in apache with 2 virtual hosts:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName test.domain.com
WSGIScriptAlias / /var/django/test/test/wsgi.py
<Directory /var/django/test/test>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *.80>
ServerAdmin webmaster#localhost
ServerName domain.com
#ServerAlias *.domain.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
But unfortunately only the first one is being called no matter what domain I put into the browser.
My expectation is that only test.domain.com will open my Django project and all other subdomains use the standard website.
What did I do wrong?
Regards
Kev
The error is here:
after replacing the dot wih a ":" the it worked perfekt.
Related
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Above is the example of https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts which I've followed to setup some sites. But what I wanna do is basically:
www.example.com?site=mynewsite.com
With htaccess: www.example.com/mynewsite.com
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com/mynewsite.com
ServerAlias www.example.com/mynewsite.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Sadly above doesn't work.
Reason why I wanna do this is because I want to generate a website using database which will be triggered based of URL.
How may I do?
You could try the obscure ServerPath directive, which maps a request to a virtualhost based on the first component of the URL path.
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 using Ubuntu 16.04.1 with Apache2.4.7
I enabled both the sites using a2ensite and reloaded apache2. It reloads successfully, but always shows sitea even for siteb.com or www.siteb.com
sitea.conf has following content:
<VirtualHost *:80>
ServerName sitea.com
ServerAlias www.sitea.com
ServerAdmin webmaster#localhost
ServerRoot /home/sitea/
DocumentRoot /home/sitea/www
<Directory /home/sitea/www>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
siteb.conf has following content:
<VirtualHost *:80>
ServerName siteb.com
ServerAlias www.siteb.com
ServerAdmin webmaster#localhost
ServerRoot /home/siteb/
DocumentRoot /home/siteb/www
<Directory /home/siteb/www>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Please suggest what am I doing wrong.
I have one Linux server with Apache installed. I configured two sites in it using VirtualHost.
I configured the two VirtualHosts for two different domain names. The configuration looks like this:
<VirtualHost 12.123.123.123>
ServerAdmin info#example-one.com
ServerName example-one.com
ServerAlias www.example-one.com
DocumentRoot /var/www/html/example-one
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost 12.123.123.123>
ServerAdmin info#example-two.com
ServerName example-two.com
ServerAlias www.example-two.com
DocumentRoot /var/www/html/example-two
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
When I visit my site example-one.com, then I see the correct website.
But when I visit example-two.com, then I see the website of example-one.com.
What am I doing wrong? I'm trying to host those two different websites under the same Apache server.
Do you have NameVirtualHost directive somewhere in your httpd config file?
This should work. Be aware that the first VirtualHost block is the default in case the http request does not match any other VirtualHost block.
For reference https://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin info#example-one.com
ServerName example-one.com
ServerAlias www.example-one.com
DocumentRoot /var/www/html/example-one
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin info#example-two.com
ServerName example-two.com
ServerAlias www.example-two.com
DocumentRoot /var/www/html/example-two
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I'm trying to enable multiple domains in my environment Development, but am not succeeding the way I tried below, at which point I'm wrong?
I installed httpd and changed DocumentRoot in httpd.conf to:
C:/Webserver/www
*I changed the Windows hosts file to(in Italics would like to access):
If I switch to 127.0.0.1 api.rotadorock the address resolves to www/ but the right is www/rotadorock/api.
127.0.0.1 localhost
127.0.0.1 webserver
127.0.0.1/rotadorock/ecommerce rotadorock
127.0.0.1/rotadorock/api api.rotadorock
127.0.0.1/rotadorock/ecommerce ecommerce.rotadorock
127.0.0.1/rotadorock/mobile mobile.rotadorock
127.0.0.1/rotadorock/sistema sistema.rotadorock
127.0.0.1/rotadorock/social social.rotadorock
*Update(windows hosts file)
I removed the hosts file changes I mentioned above, because as #Volker Birk said are not necessary. But even so, still can not access as desire (api.rotadorock/ or localhost/api.rotadorock/ and should point to C:/Webserver/www/rotadorock/api). What could be wrong?
And finally changed httpd-vhost.conf for:
NameVirtualHost webserver:80
<Directory "C:/Webserver/www">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "c:/Webserver/www"
ServerAlias localhost
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerName webserver
DocumentRoot "c:/Webserver/www"
ServerAlias webserver
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost rotadorock:80>
ServerName rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/ecommerce"
ServerAlias rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost api.rotadorock:80>
ServerName api.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/api"
ServerAlias api.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost ecommerce.rotadorock:80>
ServerName ecommerce.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/ecommerce"
ServerAlias ecommerce.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost mobile.rotadorock:80>
ServerName mobile.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/mobile"
ServerAlias mobile.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost sistema.rotadorock:80>
ServerName sistema.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/sistema"
ServerAlias sistema.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost social.rotadorock:80>
ServerName social.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/social"
ServerAlias social.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
You don't need the hosts file. Have a look into the documentation:
http://httpd.apache.org/docs/2.2/en/vhosts/name-based.html
Finally solved the problem. And I could just using the Windows hosts file and httpd-vhosts.conf httpd together.
Let me give an example of what was done to enable multiple subdomains accessing locally.
On Windows hosts file to add, for each domain and subdomain you want something like this:
127.0.0.1 api.rotadorock #my subdomain
127.0.0.1 rotadorock #my domain
And then the httpd-vhosts apache httpd:
# Accessing the API
<VirtualHost 127.0.0.1>
DocumentRoot "C:/Webserver/www/rotadorock/api"
ServerName api.rotadorock
ServerAlias ​​api.rotadorock
<Directory "C:/Webserver/www/rotadorock/api">
All Options Includes Indexes
</ Directory>
</VirtualHost>
# Accessing the domain
<VirtualHost 127.0.0.1>
DocumentRoot "C:/Webserver/www/rotadorock/"
ServerName rotadorock
ServerAlias ​​*.rotadorock
<Directory "C:/Webserver/www/rotadorock/">
All Options Includes Indexes
</Directory>
</VirtualHost>
And then that way I could access api.rotadorock/ and rotadorock/ locally. I tried all ways without the hosts file. But just gotta use it. If someone can explain to me how it should have done so it would not need to use the hosts I would be grateful.