virtualhost without real domain name - linux

I've this configuration for my virtual host and runs with real domains. For testing purpose I need create same virtual host with non real domain (i.e. domain10). Considerated that the browser check the name of domain of virtual host, I think using something like 127.0.0.1. But I've no idea to realize this.
<VirtualHost *:80>
ServerAdmin info#domain10.org
ServerName domain10.org
ServerAlias domain10.org
DirectoryIndex index.html index.htm index.php
DocumentRoot /home/domain10.org/
<Directory /home/domain10.org/>
Options -Includes -Indexes -FollowSymLinks -ExecCGI +MultiViews
AllowOverride none
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

You can use the /etc/hosts file for this purpose. There should already be a line in it beginning with 127.0.0.1. Just add domain10.org to the list of hosts that resolves to this address.
For example, if the existing line is:
127.0.0.1 localhost localhost.localdomain
Just extend it to:
127.0.0.1 localhost localhost.localdomain domain10.org
Then (on this machine only) domain10.org will resolve to 127.0.0.1. If you are testing on the same machine, you can enter http://domain10.org/ in your browser to reach your local web server.
If you need to reach this host over the Internet, then a different approach is needed. Look for a line for the external IP address of the server in its /etc/hosts file and modify it similar to the above instructions. If such a line does not exist, add one.
On the client machine, do the same (using /etc/hosts for a Linux box or %WINDIR%\system32\drivers\etc\hosts for a Windows box). You should then be able to reach the server from the client using this name.

Related

Unable to create URL with wampserver

I am trying to create a URL for a site hosted through wampserver, but no matter what I do I am unable to get the URL to work. The site is online because I am able to connect through the servers IP address, though.
(I should also mention that this site is only available on an intranet)
hosts file:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 www.socialclub.com #also tried public/private IP, still only works locally
vhosts.conf:
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerName localhost
DocumentRoot "E:\Data\Users Apps\wamp\www\socialclub"
</VirtualHost>
<Directory "E:\Data\Users Apps\wamp\www\socialclub">
AllowOverride All
Order Allow,Deny
Allow from all
Options Indexes FollowSymLinks Includes ExecCGI
</Directory>
<VirtualHost *:80>
DocumentRoot "E:\Data\Users Apps\wamp\www\socialclub"
ServerName www.socialclub.com
</VirtualHost>
Every guide I've looked at says that this should work, but it only works locally. What do I need to do for the URL to work from other computers?
Ok I think the problem is your are not understanding what the HOSTS file is used for and what its scope is.
The HOSTS file only effects the single PC that it lives on. It is used to seed the windows DNS cache at boot time. So whatever you put in this file will have no effect on any other PC in your intranet.
There are a couple of solutions :
Lets assume your PC running WAMPServer has the ip address 192.168.1.10:
You could go to each PC in your intranet and make this change to the
HOSTS file on each PC
192.168.1.10 socialclub.com
people normally think this is too much hassle especially if they have more than 5-6 PC's to mod
You could install a local DNS Server, or make use of an existing
local DNS Server. Then as long as all the PC's in your intranet are
using that DNS Server you add the domain name to that DNS Server.
people normally think this is a good idea, but it can be quite complicated to get this right and not loose access to the real DNS servers out there on the web
A couple of changes I would suggest to your httpd-vhost.conf file
First leave localhost pointing to the original wampserver homepage, but only allow access from the PC running WAMPServer. The tools on the homepage can be a very useful for debug/diagnostics/etc, but only allow access to locahost from the PC running WAMPServer.
Second put the <Directory></Directory> block inside the Virtual Host definition. This allows you to make each virtual hosts security specific to that virtual host.
# 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>
DocumentRoot "c:/wamp/www"
ServerName localhost
<Directory "c:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:\Data\Users Apps\wamp\www\socialclub"
ServerName www.socialclub.com
<Directory "E:\Data\Users Apps\wamp\www\socialclub">
AllowOverride All
Options Indexes FollowSymLinks Includes ExecCGI
# assuming your subnet equates to this range
# and you are using Apache 2.4.x
# its not necessary to allow access from all in an intranet
# in fact it might be dangerous
Require ip 192.168.1
</Directory>
</VirtualHost>

Apache virtual hosts - server ip directing to virtual host instead of /var/www/html

I have set up a linux box mainly for testing and I have got to a stage were apache, mysql and php are running. I followed tutorials on how to set up virtual hosts so I can point domains to it but something strange is happening.
This is my httpd-vhosts.conf file that I have included in my httpd.conf file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName thedomain.co.uk
DocumentRoot /var/www/thedomain
</VirtualHost>
When I go to thedomain.co.uk it is pointing to the correct place as you'd expect. But when I go to my servers ip, internal or external it is going to the same directory as the virtual host. Could you guys think of any reason that is? I would expect it to go to /var/www/html by default? Oh and I'm running CentOS 6.3
Thanks in advance for any answers!
You have used wildcard to point everything at DocumentRoot /var/www/thedomain
You need to create second listing :
<VirtualHost myotherdomain.co.uk:80>
ServerName myotherdomain.co.uk
DocumentRoot /var/www/myotherdomain
</VirtualHost>
where your other domain is whatver ip and the document root, points to your choise.
The first vhost listing is also used as the default ... so if you were to use localhost it would resolve to whatever is first in list.

How do I set up my hosts and httpd.conf files using a static IP address

I set Centos 6.3 up on a Rackspace box, using a static IP address (not a FQDN). I will be setting up virtual hosts on this box, and it seems to be working fine, but when I restart the HTTPD server, I get an error message "could not reliably determine the server's fully qualified domain name, using xx.xxx.xx.xx for ServerName" (xx.xxx.xx.xx is the static IP address for the server).
My /etc/hosts has the following in it:
27.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
xx.xxx.xx.xx name-used-for-rackspace
name-used-for-racspace is a name (not a FQDN) I used when I created the server (you have to enter a name).
I assume that I may not have to change anything in /etc/hosts, but what do I put in httpd.conf? right now, I have the following in that file:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName localhost
<Directory /var/www/html>
allow from all
Options +Indexes
</Directory>
</VirtualHost>
I also tried setting ServerName to xx.xxx.xx.xx, but I got the same error message.
This error is because you are not using a FQDN. It should not affect the operation of the webserver.
To get rid of the message on startup you'd need to configure your hosts file with the correct domain and IP address. Your httpd.conf should also use the same name (where you have localhost specified).
As long as your server is starting and you don't plan on assigning a domain to your webserver, this error can be ignored.
Example virtual host with FQDN:
<VirtualHost *:80>
ServerName www.domain.net
ServerAlias domain.net *.domain.net
ServerAdmin administrator#domain.net
DocumentRoot "/home/domain/htdocs"
<Directory "/home/domain/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
CustomLog "/home/domain/logs/access-www.log" common
ErrorLog "/home/domain/logs/error-www.log"
<IfModule mpm_peruser_module>
ServerEnvironment apache apache
</IfModule>
</VirtualHost>
Example hosts file:
127.0.0.1 localhost localhost.localdomain gentoo1
x.x.x.x gentoo1.domain.net
You need to configure the network connection with your static IP, see reference below. Otherwise, your web server is working, but it's not accessible externally.
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Configuring_IPv4_Settings.html
Then put the static IP in the httpd.conf after server name.

how to create a subdomain in a dedicated apache2 server

I want to create a subdomain I followed this steps :
cd /etc/apache2/sites-available
nano test.mydomaine.com
<VirtualHost *:80>
ServerAdmin mymail#gmail.com
ServerName test.mydomaine.com
ServerAlias www.test.mydomaine.com
DocumentRoot /var/www/testfolder/
<Directory "/var/www/testfolder">
AuthType Basic
AuthName "test"
AuthUserFile /var/www/testfolder/passwords
Require valid-user test
</Directory>
</VirtualHost>
exit and save
a2ensite test.mydomaine.com
/etc/init.d/apache2 reload
but It's not working am I missing something ?
In order for this to work, you additionally have to configure DNS resolution for the new hostname test.mydomain.com. If you are just playing with this locally and do not want to create a "real" DNS entry, you have to edit the file /etc/hosts so that your computer can resolve the hostname to an IP address. If you are running the web server on the same machine as the browser, you will want to map test.mydomain.com to 127.0.0.1. If the browser is on a different machine on your local network, you'll need to determine the server's IP address and then on the browser machine, edit /etc/hosts to add the mapping.
On Windows, the file is called C:\windows\system32\drivers\etc\hosts
A sample entry would be (for the browser running on the same machine as the server):
127.0.0.1 test.mydomain.com
If the server is at, say 192.168.0.5, the entry would be
192.168.0.5 test.mydomain.com
EDIT: If the server has a real routable IP address, then if you want the test.mydomain.com address to resolve on the global Internet you will have to get your service provider to add it to DNS. For testing purposes, you can still use /etc/hosts as described above. Just substitute the server's real IP instead of 127.0.0.1. Do this on the system where you are running the browser.

Creating subdomains in Amazon EC2

How can I create subdomains on Amazon EC2?
Is adding virtual host in httpd.conf is enough.. or any other changes also needs to be done?
Thanks
Depends on your server software. But as you mention httpd.conf, chances are good that you run Apache on a Linux distribution. If that's the case then yes, adding a virtual host is enough. Here is one way of doing it:
Purchase a domain. If you have one, skip this, we'll take example.com for this example.
Find the external IP or DNS for your EC2 instance. You probably want to associate an Elastic IP to your instance, otherwise the IP of your instance will change on reboots.
Create a DNS record for your domain, for instance a CNAME record to point to your Elastic IP/DNS name:
subdomain.example.com => ec2-xx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com
Make sure your httpd.conf contains a line to allow virtual hosts:
NameVirtualHost *:80
Create a virtual host directive:
httpd.conf:
<VirtualHost *:80>
ServerName subdomain.example.com
ServerAdmin webmaster#subdomain.example.com
DocumentRoot /var/www/example.com/subdomain
<Directory /var/www/example.com/subdomain>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/subdomain.example.com.error.log
LogLevel warn
CustomLog /var/log/apache2/subdomain.example.com.access.log combined
</VirtualHost>
6. Restart Apache
/etc/init.d/apache2 restart

Resources