old-www/HOWTO/Caudium-HOWTO/adding.html

934 lines
17 KiB
HTML

<HTML
><HEAD
><TITLE
>Adding your first server</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
REL="HOME"
TITLE="Caudium HOWTO"
HREF="index.html"><LINK
REL="UP"
TITLE="Creating your first server"
HREF="creating.html"><LINK
REL="PREVIOUS"
TITLE="Configuration InterFace (CIF.)"
HREF="cifconf.html"><LINK
REL="NEXT"
TITLE="Customizing your server"
HREF="customizing.html"></HEAD
><BODY
CLASS="sect1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Caudium HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="cifconf.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 4. Creating your first server</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="customizing.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="adding">4.7. Adding your first server</H1
><P
>&#13; In this section, I will give you a step-by-step tutorial on how to create
your first site (virtual server) with Caudium. If you want to do something
useful with Caudium, you have to create at least one virtual
server. Without this first server, Caudium will not do anything. If you use
your browser to access your server, you will only get a dialog box
prompting for the <SPAN
CLASS="abbrev"
>CIF.</SPAN
> login/password.
</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; A virtual server allows you to have several servers running on
the same port. For example you can have www.foo.com and www.foo.org running
on the same port and machine. This is why it is called virtual server.
</P
></TD
></TR
></TABLE
></DIV
><P
>&#13; To create your first server, log into the web based <SPAN
CLASS="abbrev"
>CIF.</SPAN
>. Click on the
<SPAN
CLASS="guimenu"
>Virtual Servers</SPAN
> tab, then the
<SPAN
CLASS="guibutton"
>&#13; <SPAN
CLASS="inlinemediaobject"
><IMG
SRC="images/new_virtual_server.png"></SPAN
>
</SPAN
> button.
</P
><P
>&#13; Here, you are prompted for the server name:
<DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/cif_newserver.png"></P
></DIV
>
Type in an easily identifiable
name. You also have to select the configuration type. Depending on the
configuration you choose, your server will have a different set of
modules. In other words, your server will have different capabilities. For
your first server, choose <TT
CLASS="option"
>Basic server</TT
>, and
click <SPAN
CLASS="guibutton"
>OK</SPAN
>.
</P
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="servervariables">4.7.1. Server variables</H2
><P
>&#13; Now you'll see the Virtual Servers page again. As you can see, you have two
different folders to work on: <SPAN
CLASS="guisubmenu"
>Server variables</SPAN
> (<A
HREF="adding.html#cif_ports"
>Figure 4-1</A
>) and <SPAN
CLASS="guisubmenu"
>File system</SPAN
> (<A
HREF="adding.html#cif_filesystem"
>Figure 4-2</A
>).
<DIV
CLASS="figure"
><A
NAME="cif_ports"><P
><B
>Figure 4-1. Ports in the CIF</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/cif_ports.png"></P
></DIV
></DIV
>
<DIV
CLASS="figure"
><A
NAME="cif_filesystem"><P
><B
>Figure 4-2. Filesystem in the CIF</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/cif_filesystem.png"></P
></DIV
></DIV
>
Server variables contain the URL of your site, and the port on which it will be
available. File system describes the files/directories containing the .html
and other files you want Caudium to serve.
</P
><P
>&#13; In server variables, go into <SPAN
CLASS="guisubmenu"
>Listen ports</SPAN
> and choose <SPAN
CLASS="guibutton"
>Configure a new
port</SPAN
>. Use the default values, choose <SPAN
CLASS="guibutton"
>Use these values</SPAN
>, and click
<SPAN
CLASS="guibutton"
>&#13; <SPAN
CLASS="inlinemediaobject"
><IMG
SRC="images/save.png"></SPAN
>
</SPAN
>. Now select the URL of your site, and select <SPAN
CLASS="guibutton"
>Continue</SPAN
>. You can now
go back to the page displaying all of your modules, that is, where you were
before you had gone into Server Variables.
</P
><P
>&#13; Under your server name, you'll see the status of your server. If it
contains the word <SPAN
CLASS="QUOTE"
>"Open"</SPAN
> in blue everything is okay, and you can continue
with configuring the file system.
</P
><P
>&#13; If it contains the words <SPAN
CLASS="QUOTE"
>"Not open"</SPAN
> in red, there is a problem. You can go
into the Event Log via the <SPAN
CLASS="abbrev"
>CIF.</SPAN
> tab to investigate. If you have an error <SPAN
CLASS="guiicon"
>&#13; <SPAN
CLASS="inlinemediaobject"
><IMG
SRC="images/err_3.png"></SPAN
>
</SPAN
>
<SPAN
CLASS="errorname"
>Failed to open socket on 0:80 (already bound ?)</SPAN
>, you may have another
program or Caudium itself already running on this port. To fix the problem,
identify the program which is using this port, and restart Caudium
<A
NAME="AEN579"
HREF="#FTN.AEN579"
>[1]</A
>.
To restart Caudium, go into <SPAN
CLASS="guimenu"
>Action</SPAN
>-&gt;<SPAN
CLASS="guisubmenu"
>Shutdown</SPAN
>-&gt;<SPAN
CLASS="guisubmenu"
>Shutdown Caudium</SPAN
>-&gt;<SPAN
CLASS="guimenuitem"
>Restart Caudium</SPAN
>. Wait a few seconds, and when prompted, select <SPAN
CLASS="guimenu"
>Virtual Servers</SPAN
>. Now select your
server, and you should have the word <SPAN
CLASS="QUOTE"
>"Open"</SPAN
> in blue.
</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>In the <SPAN
CLASS="abbrev"
>CIF.</SPAN
> you may wonder what are those two different protocols http and http2?</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; The difference is that http2 uses Caudium's internal memory cache while
http is plain Pike http subsystem.
So http2 is faster than http as you might expect. However,
there are some issues on some specific sites.
</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="selectingfs">4.7.2. Selecting file system</H2
><P
>&#13; By selecting a file system, you tell Caudium which files it will send to
people browsing your site. For those who know other web servers, please pay
close attention to these explanations, because Caudium is quite different
from other servers in this respect.
</P
><P
>&#13; Caudium file systems use the Unix philosophy of mount point, rather than
<TT
CLASS="constant"
>c:</TT
>, <TT
CLASS="constant"
>d:</TT
>, and so forth. The mount point concept allows
you to put your files/directory under any URL you want without changing the
files on your local file system. For example, assume you have the
following local file system:
</P
><DIV
CLASS="example"
><A
NAME="AEN605"><P
><B
>Example 4-1. Your user filesystem.</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
><TT
CLASS="computeroutput"
>&#13;/home/customers/customer1
/home/customers/customer2
/home/customers/bigcustomer3
/home/friends/franck
/home/friends/bertrand
/home/friends/didier
</TT
></PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>&#13; And suppose your URL is http://www.iteam.org/.
</P
><P
>&#13; With a default configuration, you would say that http://www.iteam.org points to /home/ so that you will have customer1 under http://www.iteam.org/customers/customer1, bertrand under http://www.iteam.org/friends/bertrand and bigcustomer3 under http://www.iteam.org/customers/bigcustomer3.
</P
><P
>&#13; But bigcustomer3 gives you a lot of money and he asks you for an URL such
as http://www.iteam.org/bigcustomer3. However, he doesn't want to be moved
from /home/customers/bigcustomer3 because of his FTP client's
configuration. Moreover, you can't move the other accounts. With the mount
point philosophy, you just have to create another mount point saying that
/home/customers/bigcustomer3 is mounted on /bigcustomer3 so that when
someone uses http://www.iteam.org/bigcustomer3, Caudium will serve them files
from /home/customers/bigcustomer3.
</P
><P
>&#13; Now let's return to our setup. Go into the <TT
CLASS="option"
>File System</TT
> module, and select
<TT
CLASS="option"
>NONE/ mounted on /</TT
> -&#62; <TT
CLASS="option"
>Path</TT
> -&#62; <TT
CLASS="option"
>Search Path</TT
>.
Here you will decide which of
your directories will be available when someone hits the root of your
server. Write, for example, <TT
CLASS="userinput"
><B
>/home</B
></TT
>.
</P
><P
>&#13; You can now launch your favorite browser to the URL of your site and
enjoy.
</P
><P
>&#13; If you don't want visitors to get a listing of your files for
security reasons, you can disable listing by setting <TT
CLASS="option"
>Directory Settings</TT
> -&#62;
<TT
CLASS="option"
>Enable directory listing per default</TT
> to <TT
CLASS="option"
>No</TT
>. Next you have to hit the
<TT
CLASS="option"
>More options</TT
> button, and then reload the module. Don't forget to click
<TT
CLASS="option"
>Save</TT
>. It is possible to put one of two <SPAN
CLASS="QUOTE"
>"magic files"</SPAN
> in any directory to
make it browsable/not browsable despite the setting in the <SPAN
CLASS="abbrev"
>CIF.</SPAN
> for that particular file system:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
><TT
CLASS="computeroutput"
>&#13;.www_browsable - the directory will always be browsable
.www_not_browsable - the directory will never be browsable
</TT
></PRE
></FONT
></TD
></TR
></TABLE
><P
>&#13; Finally, to allow bigcustomer3 to get to his URL, go to <TT
CLASS="option"
>File System</TT
> -&#62; <TT
CLASS="option"
>Copy
Module</TT
>. Next, go to <TT
CLASS="option"
>Path</TT
> -&#62; <TT
CLASS="option"
>Search Path</TT
> and type
<TT
CLASS="userinput"
><B
>/home/customers/bigcustomer3</B
></TT
>, then type <TT
CLASS="userinput"
><B
>/bigcustomer3</B
></TT
> in
<TT
CLASS="option"
>Mount point</TT
>.
</P
><P
>&#13; The <A
HREF="adding.html#cif_filesystem_example"
>Figure 4-3</A
> shows the output you
should have.
<DIV
CLASS="figure"
><A
NAME="cif_filesystem_example"><P
><B
>Figure 4-3. Example of output</B
></P
><DIV
CLASS="mediaobject"
><P
><IMG
SRC="images/cif_filesystem_example.png"></P
></DIV
></DIV
>
</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; If you created these files/directories after you point Caudium to
your site, it is safe to go in the <TT
CLASS="option"
>Actions</TT
> tab, then to <TT
CLASS="option"
>Cache</TT
> -&#62;
<TT
CLASS="option"
>Cache status</TT
> -&#62; <TT
CLASS="option"
>Flush caches</TT
>.
</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="creatingavs">4.7.3. Creating a virtual server</H2
><P
>&#13; A web server is usually running on a single port and on a single IP
address. So how can someone have different sites on this single port and
single IP? The solution is to tell Caudium that the server is different
based on the URL. This is the task of the Virtual Hosting module. As this
module is not present in the Generic template we use, you will have to add
it. Just use the <TT
CLASS="option"
>Add module</TT
> button, and click the image named <SPAN
CLASS="QUOTE"
>"Virtual
Host Matcher"</SPAN
>.
</P
><P
>&#13; You are now able to do redirection with the help of regular expressions. If
you don't know what regular expressions (<SPAN
CLASS="QUOTE"
>"regexp"</SPAN
> for short) are, check the
man page for regexp, see Pike/Perl manual, or maybe buy a book on regular
expressions. To write these redirections based on the URL, go into <TT
CLASS="option"
>Regular
expression rewrite rules</TT
> and add the following rule:
</P
><DIV
CLASS="example"
><A
NAME="AEN660"><P
><B
>Example 4-2. A simple virtual hosting regular expression.</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
><TT
CLASS="computeroutput"
>&#13;www\.virtualhost\.com www.virtualhost.com
</TT
></PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="example"
><A
NAME="AEN664"><P
><B
>Example 4-3. A better and quicker regular expression.</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
><TT
CLASS="computeroutput"
>&#13;^www\.virtualhost\.com$|^virtualhost\.com$ www.virtualhost.com
</TT
></PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>&#13; Save and type this command on your command line in order to get your
browser resolving www.virtualhost.com:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
><TT
CLASS="computeroutput"
>&#13;# echo "127.0.0.1 www.virtualhost.com" &#62;&#62; /etc/hosts.
</TT
></PRE
></FONT
></TD
></TR
></TABLE
><P
>&#13; You now have to add another virtual server with the button <TT
CLASS="option"
>New Virtual
Server</TT
> at the root of the virtual server tab. Put <TT
CLASS="userinput"
><B
>Virtual host</B
></TT
> as the
server name and choose the <TT
CLASS="option"
>Generic server</TT
> configuration type. Go into
<TT
CLASS="option"
>Server variables</TT
> -&#62; <TT
CLASS="option"
>Server URL</TT
> and type <TT
CLASS="userinput"
><B
>http://www.virtualhost.com/</B
></TT
>. You should see:
</P
><P
>&#13; This server is handled by the port in my first virtual server. Server URL:
http://www.virtualhost.com/
</P
><P
>&#13; Change the file system root and /tmp in <TT
CLASS="option"
>File system</TT
> -&#62; <TT
CLASS="option"
>NONE/ mounted on /</TT
>
-&#62; <TT
CLASS="option"
>Paths</TT
> -&#62; <TT
CLASS="option"
>Search path</TT
>.
</P
><P
>&#13; You can now point your favorite browser to http://localhost/ and
http://www.virtualhost.com/ and see the result.
</P
><P
>&#13; If you have an error telling you www.virtualhost.com is unknown check your host file.
</P
><P
>&#13; For more information about virtual hosting, see the Virtual-Web Mini-HOWTO
available at the <A
HREF="http://www.tldp.org/"
TARGET="_top"
>LDP</A
> or in
<TT
CLASS="computeroutput"
>/usr/share/doc/HOWTO</TT
> or
<TT
CLASS="computeroutput"
>/usr/doc/HOWTO</TT
> under Debian GNU/Linux.
</P
></DIV
></DIV
><H3
CLASS="FOOTNOTES"
>Notes</H3
><TABLE
BORDER="0"
CLASS="FOOTNOTES"
WIDTH="100%"
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN579"
HREF="adding.html#AEN579"
>[1]</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>&#13; To identify you can use lsof(8). If you want to know which programs
listen on port 80 just issue the following command as root<DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>You need to be root if lsof has been compiled with the HASSECURITY option which is the default for some GNU/Linux distributions</P
></TD
></TR
></TABLE
></DIV
>:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
><TT
CLASS="computeroutput"
>&#13;# lsof -i TCP:80
</TT
></PRE
></FONT
></TD
></TR
></TABLE
><P
>&#13; Here is the result:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
><TT
CLASS="computeroutput"
>&#13;COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
caudium 1001 root 12u IPv4 3993 TCP *:www (LISTEN)
</TT
></PRE
></FONT
></TD
></TR
></TABLE
></TD
></TR
></TABLE
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="cifconf.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="customizing.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Configuration InterFace (<SPAN
CLASS="abbrev"
>CIF.</SPAN
>)</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="creating.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Customizing your server</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>