Hey.
I need to set up virtual hosts on my apache server. I am new to this and have spent the last 3 days trying to find an online tutorial on how
to create one under opensuse. Could anyone please help with either a link or an explanation?
Hey.
I need to set up virtual hosts on my apache server. I am new to this and have spent the last 3 days trying to find an online tutorial on how
to create one under opensuse. Could anyone please help with either a link or an explanation?
Like most other things in openSUSE, open YAST.
You’ll find a configuration applet that’s installed most times any Service (ie Server type application) is installed, and in this case it’ll configure your Virtual Hosts as well as many other things.
HTH,
Tony
Yeah thanks but I need someone to explain how to actually set one up.
The YAST applet will set up any number of Virtual Hosts.
Is your question instead you don’t understand what a Virtual Host is, how a Virtual Hosts can share the same IP address and what are the restrictions/advantages?
Tony
Kyluke, the apache2 documentation is here:
Apache Virtual Host documentation - Apache HTTP Server
It includes some examples. When you get stuck do not hesitate to ask back here, stating what you did so far and what does not work as expected.
To get you started, this is what works for me: In /etc/apache2/httpd.local.conf I have close to the end:
# Set up virtual hosts
NameVirtualHost 62.2.xxx.xx:80
NameVirtualHost 192.168.1.10:80
Include /etc/apache2/vhosts.d/*.conf
Make sure that this local configuration file is included. In /etc/sysconfig/apache2 check that this is set:
APACHE_CONF_INCLUDE_FILES="/etc/apache2/httpd.local.conf"
There are two sets of virtual hosts in my configuration. One for the outside and another one for the LAN users. The configuration files in /etc/apache2/vhosts.d/mydomain.conf start like this:
# VirtualHost template mydomain.conf
# Note: to use the template, rename it to /etc/apache2/vhost.d/yourvhost.conf.
# Files must have the .conf suffix to be loaded.
#
# See /usr/share/doc/packages/apache2/README.QUICKSTART for further hints
# about virtual hosts.
#
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost 62.2.xxx.xx:80 192.168.1.10:80>
ServerAdmin [email]admin@mydomain.com[/email]
ServerName www.mydomain.com
ServerAlias mydomain.com
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
DocumentRoot /srv/www/htdocs/mydomain
# don't loose time with IP address lookups
HostnameLookups Off
# needed for named virtual hosts
UseCanonicalName On
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/srv/www/htdocs/mydomain">
(((your configuration stuff here)))
</Directory>
</VirtualHost>
Please note that this is still on an openSUSE 11.2 server, but I do not think that the basic configuration had any relevant changes.
Thanks vodoo. I have been trying to get it to work since you posted this but still having trouble. I still don’t quite understand how to set it up.
I understand what a virtual host is etc and what I would like to set up is a name based virtual host. I have followed the instructions on the apache site but it seems the config files are in different locations or something.
Okay I got my virtual hosts set up. My next question is.
How do I access them for development using localhost?
The first one works and I know it should always pick the first one but how do I access the 2nd one?
Assuming you went for name virtual hosts, you have to address them using aliased domain names. Simplest way is to add aliases for 127.0.0.1 in /etc/hosts:
127.0.0.1 localhost virtual1 virtual2 virtual3
and so on. Then in the browser you have to use http://virtual1/ and so on.
Thanks guys it’s all up and running now :).
Last question. How do I access these different servers from outside of my network? ie. Over the internet.
I only use my IP address to connect btw.
Last question. How do I access these different servers from outside of my network? ie. Over the internet.
I only use my IP address to connect btw.
Sorry, no way. You explicitely wanted name based virtual hosts. The domain name you are using to access the server is used to decide what virtual host you want to contact.
To make this work as seen from the outside you have to use a domain name for each vhost and set up DNS for them. Each domain name points to your (single) public IP number, but is handled differently according to it’s domain name.
Hi Guys, hope to get any answers here
Have a problem with virtual hosts, done all what you suggested but still doesn’t work.
I have simple test LAN at home, set up apache, DNS also but still only test web site works bot other virtual server no…
Any sugestions?
You nee to describe what you’ve done, what you’ve tried.
Although the OP in this thread didn’t seem to follow my advice to install and use the YAST web server applet to configure, IMO it’s still the simplest way to get started. To install,
zypper in yast2-web-server
After that, you’ll see an “httpd server” applet in YAST. With that, you can configure the default website, name-based virtual webservers and IP-based webservers fairly automatically and easily.
TSU
I have set up apache on sles with and without yast, using several descriptions over internet and suse bible… but all i get is when I type in ip of a server, web site is on, but other (virtual host) doesnt work.
I have checked hosts file (added VH manualy) but still the same…
Even tryed set up dns but still the same…
I want to test VH on simple LAN only, no complications or what so ever…
can U help?