Virtual Host setting not working - apache

I am hosting two domains on a vps server. The domains, let say www.abc.net(or abc.net) and www.xyz.net(or xyz.net) have following config
<VirtualHost *:80>
ServerName abc.net
ServerAlias www.abc.net
ServerAdmin webmaster#localhost
DocumentRoot /var/www/abc.net
ErrorLog ${APACHE_LOG_DIR}/abc.net.error.log
CustomLog ${APACHE_LOG_DIR}/abc.net.access.log combined
</VirtualHost>
and
<VirtualHost *:80>
ServerName xyz.net
ServerAlias www.xyz.net
ServerAdmin webmaster#localhost
DocumentRoot /var/www/xyz.net
ErrorLog ${APACHE_LOG_DIR}/xyz.net.error.log
CustomLog ${APACHE_LOG_DIR}/xyz.net.access.log combined
</VirtualHost>
apart from these I have default apache2 00-default-site.conf (unchanged)and rutorrent.conf
<VirtualHost *:80>
ServerAlias *
DocumentRoot /var/www/
CustomLog /var/log/apache2/rutorrent.log vhost_combined
ErrorLog /var/log/apache2/rutorrent_error.log
SCGIMount /rutorrent/RPC2 127.0.0.1:5000
<Directory "/var/www/rutorrent">
AuthName "user1"
AuthType Basic
Require valid-user
AuthUserFile /var/www/rutorrent/.htpasswd
</Directory>
</VirtualHost>
Assuming my ip as t.u.v.w I have following /etc/hosts file set
127.0.0.1 localhost
127.0.1.1 template.pcsmarthosting.co.uk template
t.u.v.w abc.net
t.u.v.w xyz.net
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
I am able to access www.abc.net correctly as it goes to correct folder, however www.xyz.net goes to /var/www/ same as http://t.u.v.w
www.xyz.net doesn't work even when it is the only enabled site.
How do I fix this?

Systems hostname might be www.xyz.net , which means that 000-default acts as if it has "ServerName www.xyz.net" implicitly.
You should put a dummy ServerName in the 000-default so there's no risk.

Related

Setup zend skeleton application

I am trying to setup the zend skeleton application in my Windows 10 machine. However, since port 80 was not available, I am trying to configure on port 8080. But every time I do not get the zend skeleton page. I only get the apache page that says "It works". Pls suggest what I am doing wrong.
In apache httpd.conf, I made below changes:
Listen 8080
ServerName localhost:8080
In httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "${SRVROOT}/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "${SRVROOT}/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost *:8080>
ServerName zendskeleton.localhost
DocumentRoot C:/zendskeleton/public
SetEnv APPLICATION_ENV "development"
<Directory C:/zendskeleton/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
In Windows hosts file:
127.0.0.1 zendskeleton.localhost localhost

Apache Virtual Hosts on different domain names AND ports

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.

Virtual Hosts on WAMP causing 403 forbidden on localhost... other aliases still work

I just realized that nothing else on WAMP is accessible unless it's under the virtual host alias. For example: if I name my vHost 'mysite.dev', I can only access mysite.dev and everything else gives a 403 forbidden error. If I add a vHost called anothersite.dev in addition to mysite.dev, only those sites can be accessed. The only thing under localhost that I can access is PHPMyAdmin. I have uncommented the line that includes vHosts.conf in the Apache httpd.conf file. This problem does not happen until I modify the vHosts.conf file. Here is the config for the other files:
vHosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "W:/wamp/www/mysite"
ServerName mysite.dev
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
Windows hosts file:
127.0.0.1 localhost
127.0.0.1 mysite.dev
Ok first, the first 2 VHOST definitions in the httpd-vhost.conf file (vhost and vhost2) are examples, supplied by Apache, to help you get started and of course point to folders that do not exist so and should be removed.
Second When you create a Virtual Host you should include the access privilages for the VHOST in a <Directory....> group.
Third, you should always create a VHOST for localhost as once VHOSTs are created Apache ignores the localhost definition in httpd.conf
So your httpd-vhost.conf file should look like this
# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
ServerAdmin webmaster#homemail.net
DocumentRoot "W:/wamp/www"
ServerName localhost
<Directory "W:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "W:/wamp/www/mysite"
ServerName mysite.dev
ErrorLog "logs/mysite.dev-error.log"
CustomLog "logs/mysite.dev-access.log" common
<Directory "W:/wamp/www/mysite">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
Once you have done this, you now need to edit your c:\windows\system32\drivers\etc\hosts file to look like this. You need to have admin privilages to edit this file, also some anti virus suites also protect this file, so you may need to stop that protection temporarily in order to amend this file.
127.0.0.1 localhost
127.0.0.1 mysite.dev
::1 localhost
::1 mysite.dev
Then restart the dnscache to pick up these changes, from a command line also started with admin privilages.
net stop dnscache
net start dnscache
This post may help you understand more about Virtual Hosts

Fedora Apache: VirtualHost not picking up DirectoryIndex

I am having a problem with virtualhosting on my fedora 18 box.
http://127.0.0.1 works correctly and brings up index.html
http://127.0.0.1:9000 also works correctly.
http://localhost works
http://localhost:9000 does NOT work.
It just redirects to http://localhost
Why is not able to treat localhost and 127.0.0.1 the same way?
Here is the contents of my httpd-vhosts.conf:
Thanks in advance.
Listen 9000
DirectoryIndex index.html welcome.html
NameVirtualHost *:80
NameVirtualHost *:9000
<VirtualHost *:80>
ServerName saraslights
ServerAdmin ratteri#gmail.com
ServerAlias saraslights
DocumentRoot "/var/www/html/opencart"
ErrorLog "logs/saraslights-errors.log"
CustomLog "logs/saraslights-access.log" common
</VirtualHost>
<VirtualHost *:9000>
ServerName wordpress
ServerAdmin ratteri#gmail.com
ServerAlias wordpress
DocumentRoot /var/www/html/wordpress
ErrorLog "logs/wordpress-errors.log"
CustomLog "logs/wordpress-access.log" common
</VirtualHost>

How to enable multiple domains and or subdomains with apache httpd server

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.