Forum Moderators: phranque
I currently have ALL virtual servers running ALL scripts somehow, but that's not what I want. I need each virtual server to only run it's own scripts not all that are on the server.
I've mucked around making cgi-bin directories where I want them, then trying scriptalias, and stuff like that to make them work, but nothing does. But, as I said, I really have no idea what I'm doing in there so I could have it all wrong.
Currently this works for everything:
/var/www/cgi-bin
But, I want this to work too:
/var/www/html/virtual_server/cgi-bin
Can someone clue me in as to how to do that? I'm tearing my hair out over this! TIA!
<VirtualHost *>
DocumentRoot "/var/www/html/virtual_server/public_html"
ServerName www.example.com
ServerAlias example.org
[b]ScriptAlias /cgi-bin/ /var/www/html/virtual_server/cgi-bin[/b]
</VirtualHost> Personally I prefer creating standard UNIX accounts for each virtual host and storing everything under the account's home directory, eg.
/home/craigf/public_html - it makes it easier for configuring the FTP or shell access, and you can place the /home on a separate partition (or even a separate hard drive): <VirtualHost *>
DocumentRoot "/home/craigf/public_html"
ServerName www.example.com
ServerAlias example.org
[b]ScriptAlias /cgi-bin/ /home/craigf/cgi-bin[/b]
</VirtualHost> What does your current VirtualHost container look like?
Now, I'm wondering why this works:
ScriptAlias /cgi-bin/ /var/www/html/virtual_server/cgi-bin
But this does not:
ScriptAlias /var/www/cgi-bin/ /var/www/html/virtual_server/cgi-bin
I'm sure that makes sense somehow, but since I see the cgi-bin living at "/var/www/cgi-bin/" I don't get why it's not used that way. Why does it work that way?
I prefer creating standard UNIX accounts
I'm interested in anything that will make maintaining the server easier, could you explain that more? To be honest I don't even know what a UNIX account is really, but your second example looks a lot more like what I'm used to dealing with when I've used virtual hosting accounts in the past.
ScriptAlias /var/www/cgi-bin/ /var/www/html/virtual_server/cgi-bin
The above would give you a cgi-bin at example.com/var/www/cgi-bin - the first variable of the ScriptAlias (/cgi-bin/) refers to the path from the document root not the server root.
For the user account approach: I assume you have a dedicated server with root access. There are control panels which can do all of this, but here's the manual way.
Say you want to have a virtual server for the site example.com. Firstly, you check that Apache is set up to support user directories: open up
/etc/apache/httpd.conf (or the location of your Apache configuration file) and look for UserDir. You should have something like this: <IfModule mod_userdir.c>
UserDir public_html Assuming all is well, then you should set the public_html, and cgi-bin directories to be created by default:
cd /etc/skel
mkdir public_html
mkdir cgi-bin In fact, you should create all the files and directories that you want created automatically when you create a new account - for example a simple index.html file in public_html as a holding page.
Next, you need to create a user account for the new site example.com. We'll use the username "example". As root, you type the command:
adduser example Then you type in the password twice and fill in the other details if you want. Note that If you don't want the user "example" to have command line access you should set their default shell to
/bin/false. The adduser command will create a home directory as /home/example and including all the directories and files from /etc/skel. To test that all is working fine, open a browser window and navigate to:
http:// <your IP address> /~example/
The index.html file within
/home/example/public_html should show up (or a directory listing if there is no index.html). If your FTP is set up correctly, you should also be able to connect to your server using the "example" username and password, and be dropped directly into the appropriate home directory. From then on in it's plain sailing: you create the VirtualHost container with all the details as before. You can set it up with custom access and error logs for each virtual host placed in the user's home directory (create a logs directory next to public_html). If you have a lot of virtual hosts, check out the "Mass virtual hosting" guide in the Apache documentation.
One last thing: do you have a test server? It doesn't have to be anything fancy: my test server is a Pentium 133Mhz which is ten years old, running Debian. Grab any old machine and install the same or similar distro as you are using on your main server, add it to your local network and connect to it exclusively via telnet/ssh. You can test everything more easily without breaking stuff on your main machine!
I am using webmin, but getting to know the manual way is probably a good idea for me at this point.
> it makes it easier for configuring the FTP or shell access
does this offer any other benefits? it's going to be a bit before I have the time to stop and fool with this, so I'm just wondering.
also, this all still looks a bit greek to me. will this be a pain since I already have a couple sites running that are not set up this way?
thanks for the great info encyclo!