LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Please check my virtualhost... (https://www.linuxquestions.org/questions/linux-server-73/please-check-my-virtualhost-637654/)

phantom_cyph 04-24-2008 08:42 PM

Please check my virtualhost...
 
I need to set up a virtualhost (for the first time), and I wanted to make sure I had it set up correctly before I uncommented it.

How does this look? (link to copy of httpd.conf)

billymayday 04-24-2008 09:04 PM

Looks OK to me. I'd put the ServerName at the top to make it more readable, but it doesn't actually matter.

I assume that your DocumentRoot is correct, etc.

Give it a try - it won't damage anything is you do have a mistake

Wim Sturkenboom 04-24-2008 11:54 PM

You have Slackware12 in you signature, however not sure if that's the distro that you're using for your webserver.

If you run a stock Slackware 12 box, vhosts are defined in /etc/httpd/extra/httpd-vhosts.conf. You uncomment one line in /etc/httpf/httpd.conf as shown below to activate it; this line is commented out (so non-functional) by default
Code:

Include /etc/httpd/extra/httpd-vhosts.conf
The content of my httpd-vhosts.conf:
Code:

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

# catch-all
<VirtualHost *:80>
    ServerAdmin my@email.here
    DocumentRoot /srv/httpd/htdocs
    ServerName btd-techweb02
</VirtualHost>

# site 1
<VirtualHost *:80>
    ServerAdmin my@email.here
    DocumentRoot /home/wim/www/site1/web
    ServerName site1.btd-techweb02
    ErrorLog /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log common

#WimS
# this is required to prevent message 403 "Forbidden"
    <Directory "/home/wim/www/site1/web">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

# site2
<VirtualHost *:80>
    ServerAdmin my@email.here
    DocumentRoot /home/wim/www/site2/web
    ServerName site2.btd-techweb02
    ErrorLog /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log common

#WimS
# this is required to prevent message 403 "Forbidden"
    <Directory "/home/wim/www/site2/web">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>


# site3: stringdokter.com
<VirtualHost *:80>
    ServerAdmin your@email.here
    DocumentRoot /home/phantom_cyph/www/stringdokter/web
    ServerName www.stringdokter.com
    ErrorLog /var/log/httpd/stringdokter.com-error_log
    CustomLog /var/log/httpd/stringdokter.com-access_log common

#WimS
# this is required to prevent message 403 "Forbidden"
    <Directory "/home/phantom_cyph/www/stringdokter/web">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

I have added your site (italic) to show you, but not tested it.

As you might notice, I don't use the standard apache directory for the websites, but the user's home directory. Reason is that I consider it easier when it comes to ftp. Usually a system administrator wants to jail ftp-users to their home directory and I have seen too many questions regarding permissions and access to /var/www/htdocs in relation with ftp. In the setup that I have choosen, a user can ftp to his/her home directory and descend into the web directory to update the website. Disadvantage however is that if apache needs to write files, you need to open the permissions a bit.

My directory tree for the sites looks like this:
Code:

/home
  |
  +--- wim
  |    |
  |    +--- www
  |          |
  |          +--- site1
  |          |    |
  |          |    +--- web (externally accessible files go here, e.g. webpages)
  |          |    |    |
  |          |    |    +--- files (directory that can be written by apache)
  |          |    |
  |          |    +--- inc (files required for the website, but need to be kept secure, go here)
  |          |
  |          +--- site2
  |          |    |
  |
  +--- phantom_cyph
  |    |
  |    +--- www
  |          |
  |          +--- stringdokter
  |          |    |
  |          |    +--- web
  |          |    |    |
  |          |    |    +--- files
  |          |    |
  |          |    +--- inc
  |          |

I saw that you have php enabled, so here a small tip which also explains the inc directory in my setup:
I don't want php code that e.g reveals login credentials for a database to be accessible from the outside world (anything in web is), so that goes in inc. The webpage that uses that code will go in web and will use a include statement to access it.


Sorry for the long story, I hope it helps a bit in understanding things.


All times are GMT -5. The time now is 08:00 PM.