O'Reilly Book Excerpts: Linux Cookbook
Excerpt from Linux Cookbook, Part 2by Carla Schroder
Editor's note: In Part 1 of this two-part series, Carla Schroder, author of Linux Cookbook, shared three recipes, with tips on installing a program for easy uninstall, killing user processes, and better logins without passwords. This week, in the final part, she offers two more tasty treats, including tips on running different window managers simultaneously with Xnest and hosting multiple domains with Apache. Enjoy!
15.12 Running Different Window Managers Simultaneously with Xnest
You have all these great window managers and desktop environments installed— KDE, Gnome, Enlightenment, Fluxbox, XFce, and such—and you would like to run some of them simultaneously. You know you can start up separate additional X sessions, or log out of X and start up in another window manager, but you wonder if there isn't a way to run them at the same time.
Xnest, the "nested X server," is just the tool for the job. Xnest allows you to run additional X sessions inside of already running X sessions.
Open a command shell in any X session—let's say you're running IceWM—and fire up Xnest:
$ Xnest -ac :1
You should see a blankscreen with an X cursor in the middle. Now you can open a window manager. This example starts up WindowMaker:
$ wmaker -display :1
Now you can start up another one. From a command shell on IceWM, enter:
$ Xnest -ac :2
Some window managers or desktop environments, such as Gnome, need to start from an xterm in the Xnest window. First start up an xterm:
$ xterm -display :2
Then start Gnome from the xterm:
You can start up yet another Xnest session from any available terminal in any of the windows:
$ Xnest -ac :3
You can continue to open more window managers until your system resources are exhausted and everything slows to a crawl. Figure 15-1 shows Gnome inside of IceWM, on KDE.
X sessions are numbered from 0, so the default X session is always :0. The -ac option to Xnest specifies the session number for the new display. Keep trackof your whereabouts by checking the DISPLAY value:
$ echo $DISPLAY :0.0
The -ac option disables access controls. Otherwise, X will not let you open any applications. Xnest uses the same options as the X command—see xserver(1x). When you get several window managers going, you might see an error message like this, and the new one won't start:
$ gnome-session gnome-session: you're already running a session manager
No problem. Just track it down and kill it:
$ echo $SESSION_MANAGER local/windbag:/tmp/.ICE-unix/2774 $ rm /tmp/.ICE-unix/2774
and now Gnome will start.
Figure 15-1. Gnome
- xnest(1), xserver(1)
- Window managers for X (http://www.plig.org/xwinman)
22.10 Hosting Multiple Domains with Apache
You want to host several different domains on a single Apache server,sharing a single IP address. You've already registered all your domain names and have DNS in place for each one.
Use Apache's VirtualHost directives to set up name-based virtual host support. Here is a sample httpd.conf entry for serving two different domains:
NameVirtualHost *:80 <VirtualHost *:80> ServerName www.tuxcomputing.com ServerAlias tuxcomputing.com *.tuxcomputing.com DocumentRoot /var/www/tuxcomputing ServerAdmin email@example.com </VirtualHost> <VirtualHost *:80> ServerName www.bratgrrl.com ServerAlias bratgrrl.com *.bratgrrl.com DocumentRoot /var/www/bratgrrl ServerAdmin firstname.lastname@example.org </VirtualHost>
Each domain has its own separate root directory where the site files are stored. This allows you to easily set up subdomains,such as webmail.bratgrrl.com and wacko.games.tuxcomputing.com. However,this does not work by magic--you need to create DNS A records for each domain and subdomain.
Note: Once you start using virtual hosts,each of your domains must have a VirtualHost directive. If you start out with a single domain,you'll have to create a VirtuaHost entry for it. VirtualHost directives override the global directives in httpd.conf. Almost any httpd.conf directive can be used in your VirtualHost stanzas,so you can customize each virtual host as you need.
Name-based virtual hosting is the easiest way to serve up multiple domains from a single Apache server. Configuring A records for a lot of subdomains can get a bit wearisome,but it's better than using a domain wildcard. A domain wildcard allows all traffic that includes your domain name to hit your servers. For example:
Spammers will abuse a domain wildcard beyond belief,so you want to be careful to configure only your exact domain names in your DNS records. It is acceptable to use domain wildcards in your VirtualHost directives, because only domain names explicitly defined in DNS will ever see any traffic.
Here is what each directive does:
- NameVirtualHost *:80
This tells Apache to listen for requests for these virtual hosts on all network interfaces,on port 80. It is best to specify an IP address or,as in this case,a wildcard. Don't use domain names,because the server will then have to do DNS lookups,which will slow it down. Never leave it blank. Any IP/port setting here must also match the Listen directive. For example:
Listen 80 Listen 192.168.1.5:8080
NameVirtualHost can use either of these. Remember that when you use a nonstandard port, such as 8080, users must specify the port in their URLs:
- <VirtualHost *:80>
- This must match the NameVirtualHost values.
- ServerName www.tuxcomputing.com
- This should match a DNS A record.
- ServerAlias tuxcomputing.com *.tuxcomputing.com
- Here you can define other server names; users can now connect to www.tuxcomputing.com,or tuxcomputing.com,or <any subdomain> .tuxcomputing.com. Note that every subdomain must have a specific DNS A record pointing to it—don't use DNS wildcards! This is asking for trouble with spammers and other loathsome subhumans who infest the Internet,looking for things like this to exploit.
- DocumentRoot /var/www/tuxcomputing
- This specifies the local directory where the site files are stored.
- ServerAdmin email@example.com
- This provides a contact address to which users can report problems.
- Chapter 4 of Apache: The Definitive Guide
Return to the Linux DevCenter.