configuration of domainname in httpd.conf and /etc/hosts - apache

I am facing an issue with configuring domain name in my httpd.conf file. Entry in httpd.conf file.
Listen sample.com:443
<VirtualHost sample.com:443>
SSLEnable
ServerName MyIHSInstalledServerName
</VirtualHost>
KeyFile /serverPath/keyfile.kdb
SSLDisable
SSLTrace
Now I am confused on what should be the entry made in /etc/hosts
{IP} sample.com sample. Here what is the IP I should mention and is my entry in httpd.conf file correct? Please help.

Your /etc/hosts file is not really relevant to your Apache config.
For SSL virtual hosts, use either the actual ip address that you want your SSL httpd daemon to be bound to
eg
<VirtualHost 10.1.1.1:443>
or use:
<VirtualHost _default_:443>
which will bind the daemon to the first ip address not in use by any other SSL virtual host, which should work in the vast majority of cases
The name of the service is only relevant to the ServerName directive. If you include that, the httpd daemon will only respond to requests that include that name in the header.

Related

ServerName for local Apache2 instance

I wanted to create my own self signed SSL certificate and add it to the local Apache2 instance (i.e. changing http://localhost/ to https://localhost/). However, I'm stuck at the part on what to put under the server IP in default-ssl.conf file. I'm referring to this resource to create the SSL certificate. I tried putting "127.0.0.1", "localhost" and the private IP address (in this case it's 10.0.2.15) under the "ServerName" part. However, it's still failing with the following error.
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
(13) Permission denied: make_sock: could not bind to addres 0.0.0.0:80
no listening sockets available, shutting down
Can anyone please give some hints on what went wrong? I'm running out of ideas (or things to google) why the server name is wrong...
The first few lines of my default-ssl file:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin temp#temp.com
ServerName localhost
Ironically the issue seems to have resolved by itself... Not too sure what happened but now I'm facing another issue (which I posted on Unable to change the document root of https://localhost/)
I kept the code as it is:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin temp#temp.com
ServerName localhost

apache httpd name-based virtual host: use ip or domain name?

In Apache web server, when using name-based virtual hosting you can use either the IP or the actual domain name in the VirtualHost directive.
(Name-based virtual hosting on Debian is enabled via /etc/apache/ports.conf through NameVirtualHost <ip>:<port> statement, where <port> has to be the same one as in a Listen directive.)
So, then this:
<VirtualHost 10.0.0.1:80>
...
or this:
<VirtualHost sub.domain.tld:80>
...
will equally work.
What are the differences, and which approach should be preferred?
Using an IP address is preferred so that your config can be parsed even if DNS resolution fails.
You can use the ServerName directive to control which hostname the VirtualHost block applies to, without triggering a DNS resolution:
<VirtualHost 10.0.0.1:80>
ServerName sub.domain.tld
...
</VirtualHost>
http://httpd.apache.org/docs/current/dns-caveats.html has more examples of good and bad practice.

creating Subdomain in Xampp doesn't work

I made a subdomain on Localhost over Xampp with following code in httpd-vhosts.conf (guide from different sources)
NameVirtualHost *:80 (uncommented by removing #)
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/sub
ServerName sub.localhost.com
</VirtualHost>
and following code into hosts of Windows/System32/drivers/etc/
127.0.0.1 localhost
127.0.0.1 sub.localhost
now the problem is subdomains are not working. One more thing I just noticed that when I start apache service in Xampp Control Panel, it has set the port as 80,443 for Apache which is good but as soon as I hit localhost in browser it changes port to different ports like 52352 etc. I also tried to setting up code in hosts file as
127.0.0.1:80 localhost
127.0.0.1:80 sub.localhost
but not working. I tried many other things but all in vein. While a month before I created successfully in the same Xampp Installation. off course i have created sub directory in htdocs.
Make sure you have this line uncommented in httpd.conf
#Include conf/extra/httpd-vhosts.conf
Remove this line in httpd-vhosts.conf (or comment it out):
NameVirtualHost *:80
Make sure you have a blank line at the end of both httpd-vhosts.conf and hosts, and make sure you're using tabs to separate IPs with their associated domains in the hosts file.
Make sure another application is not using ports 80, 443 (Skype for example).
Ultimately, restart your Apache server.
If you want to create sub directory, *emphasized text*127.0.0.1:80 localhost*emphasized text*
the settings back to original and change only *emphasized text*DocumentRoot C:/xampp/htdocs/sub*emphasized text*

Set up host file using port

I want to setup my host file to
127.0.0.2:5050 domain2.com => this is a local domain
when a type in my browser domain2.com, this return me : HTTP Error 404. The requested resource is not found.
i use this in apache
<VirtualHost 127.0.0.9:5050>
ServerAdmin info#domain2.com
DocumentRoot "C:/Users/My_Dir/LOOP/WebEnginer-2011/domain2_Dir/"
ServerName domain2.com
DirectoryIndex index.php index.html index.htm
ServerAlias www.domain2.com
ErrorLog "c:/wamp/xxxx/xxxx.log"
CustomLog "c:/wamp/xxxx/xxxx.log" common
</VirtualHost>
<VirtualHost 127.0.0.9:5050>
ServerAdmin info#domain2.com
DocumentRoot "C:/Users/My_Dir/LOOP/WebEnginer-2011/domain2_Dir/admin_Dir/"
ServerName admin.domain2.com
DirectoryIndex index.php index.html index.htm
ServerAlias www.admin.domain2.com
ErrorLog "c:/wamp/xxxx/xxxx.log"
CustomLog "c:/wamp/xxxx/xxxx.log" common
</VirtualHost>
but when i type 127.0.0.2:5050 i can see a web page. I want to use subdomain like admin.domain2.com
i can't use port 80 because IIS use that port.
How can i set up my host file to listen domain2.com?
That won't work since the hosts file only serves the purpose of mapping a hostname to an IP-address. The port number of a service is a different concept and is not handled by the "hosts" file nor the DNS-System. In Short: you can't supply a port number in the "hosts" file.
If your Webserver works on another port, you have to supply that information in the URL: http://domain2.com:5050.
The only other solution is to configure your Webservers to listen on a specific IP so that they don't interfere with each other. For example the IIS could listen on 127.0.0.1 and the Apache on 127.0.0.2 (the way you have already configured it).
There's a HOWTO for achieving that with the IIS. I'm not sure if that works for 127.0.0.x-IP's but I think it's worth a try.
It might be:
Your DNS resolver not resolving that properly
Some Apache webserver misconfiguration
Try this to get more information about that:
What if you ping domain2.com?
Also, try what happens if you put something like domain2.local in your hosts file. It might be some windows security c** disallowing you to overwrite the ip of an existing domain.
Why didn't you use 127.0.0.1? That should be fine, however
Make sure you have a properly configured VirtualHost that accepts requests to "domain2.com", or you just have a default virtualhost.
EDIT
What did you actually add to hosts file? The correct syntax would be:
127.0.0.2 domain2.com

Multiple Apache2 vhosts are pointing to the same website

I'm running Apache2 on Ubuntu 10, and I have my site configuration files laid out numerically and in order. My default server is psychedeli.ca, but I also run another site off the same box at mahoganytales.com. Currently, both of these domains point to the same site (the one for psychedeli.ca). The declaration NameVirtualHost *:80 is in my ports.conf file, so I'm pretty sure my global server config checks out. How can I fix this?
Here are my vhost files:
001-psycho
<VirtualHost *:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
</VirtualHost>
002-mahogany
<VirtualHost *:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
</VirtualHost>
try create new conf file at /etc/apache2/conf.d, e.g., vhosts.conf
with this content in it:
NameVirtualHost *
It looks like the default configuration is in effect rather than your host entries. Following is the procedure that works in Ubuntu Apache2.
First,
create a VirtualHost in /etc/apache2/sites-available/somesite,
then a2ensite somesite to make it live.
Finally, /etc/init.d/apache2 restart to restart apache.
If you think, you have followed the above steps, then can you please confirm, that you have your hosts files in /etc/apache2/sites-enabled/?
Each domain name needs to have it's own single unique ip address, that's how different sites are found.
By using the *:80 in the virtual host directive, you're instructing Apache to listen on all IP addresses, port 80 and send it to this directory. With your second vhost, you're doing the same thing (All IP's port 80, and send it there). Well, since you're giving it two conflicting statements, it takes the first match, and uses it.
If you want to serve multiple websites, each must answer to it's own unique IP address, ie:
site aaa.com - 145.25.82.110
site bbb.com - 145.25.82.111
From there, each vhost entry will listen on it's own ip address and port for each site. In the OP's case the vhost needs to change to (using the example IPs):
&ltVirtualHost 145.25.82.110:80>
DocumentRoot /var/apps/psycho/public
ServerName psychedeli.ca
&lt/VirtualHost>
&ltVirtualHost 145.25.82.111:80>
DocumentRoot /var/apps/mahogany/public
ServerName mahoganytales.com
&lt/VirtualHost>
This instructs the server to listen on static IP 1 port 80 (as defined in the named.conf and associtated bind config files, and send it to the first site base directory, and any calls on the second static IP port 80 and send it to the second site base directory.
As for configuring bind/named, that's beyond the scope of this question...