Virtual Host for ip/user

I want to be able to go to the address myserversip/username and see the site I have created in that users public_html directory.

My server is running Apache2 on Ubuntu, 9.10.

I know this has to be possible since I can access phpmyadmin via myserversip/phpmyadmin

So I created a new virtual host like this:


<VirtualHost *:80>
DocumentRoot /home/user/public_html
ServerName myserversip/user
ServerAlias myserversip/user
  ServerAdmin david@davidreagan.net
  <Directory />
    Options FollowSymLinks
    AllowOverride none
  </Directory>
</VirtualHost>

After restarting apache, it gives me a 404 error when I try to go to ipaddress/user.

What should I do?

You were correct to use the /etc/hosts file, that solves the DNS end of the problem.

The problem now lies therein that mainsite.net is now served from /home/mainsite/public_html and the OP would also like to serve mainsite.net/username from /home/username/public_html

As I’ve never done something like this I wouldn’t know how to set it up (beside suggestion mass virtual hosting, which to me seems way over the top to solve this problem, so it’s not a good suggestion). David, your turn again :slight_smile:

This article might be interesting for you: http://caffeinated-geek.com/blog/?p=133

Huh, interesting. So it’s because of my folder structure. I find that kinda odd…

I assume that if I had multiple ip addresses, I could get it working, since that’s how I set up separate sites on my local desktop test machine.

I suppose what I will have to do is restructure my folders. Good thing I just have my personal site on there right now.

Would a good structure be:
/home/mainserverdomain/user1/public_html
/home/mainserverdomain/user2/public_html
/home/mainserverdomain/user3/public_html

Jerrac,

This is a DNS problem so look for your DNS settings to configure your newsite. I’m not sure where those are on a 'nix box so let Stomme poes (or ScallioXTX?) direct you there.

Regards,

DK


127.0.0.1     localhost localhost.localdomain
{myserverip}     thecreek
{myserverip}     mainsite.net
{myserverip}     www.mainsite.net

(you DID update your server’s hosts file, didn’t you?).

If you can’t tell, I’m pretty new to managing my server. So, no. I didn’t edit the hosts file. All the how to’s I found said I just needed to add a new vhost. How exactly should I edit it?

currently, /etc/hosts looks like this:


127.0.0.1     localhost localhost.localdomain
{myserverip}     thecreek

Thanks for your help so far. :smiley:

That still looks like it’s properly formatted (should not cause the server to not start). Comments, though:


<VirtualHost [COLOR="Gray"]{serverip}[/COLOR]:80>
DocumentRoot /home/mainsite/public_html
  ServerAdmin david@mainsite.net
  <Directory />
    Options FollowSymLinks
    AllowOverride All
  </Directory>
[COLOR="RoyalBlue"]# my test server is configured as follows:  
#<Directory />
#    Options FollowSymLinks
#    AllowOverride All
#    Order deny,allow
#    Deny from all
#</Directory>
# Note that I was WRONG with my insistence that
# a space was required in the <Directory /> line
[/COLOR]


  ErrorLog /var/log/apache2/error.log
  LogLevel warn
  CustomLog /var/log/apache2/access.log combined
  <Directory "/home/mainsite/public_html">
    allow from all
    Options +Indexes
    RewriteEngine on
    #RewriteBase /fbk/ctb
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteCond %{REQUEST_URI} ^/fbk/ctb/(.*)$
    #RewriteRule ^(.*)$ /fbk/ctb/index.php?q=$1 [L,QSA]
    [COLOR="Red"]RewriteBase /[/COLOR]
# I always comment on RewriteBase (when a mod_alias Redirect is not used)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]    
  </Directory>
ServerName mainsite.net

# The following should also give you the www'd version
[COLOR="RoyalBlue"]ServerAlias www.mainsite.net[/COLOR]  
</VirtualHost>

<VirtualHost [COLOR="RoyalBlue"]{serverip}[/COLOR]:80>
DocumentRoot /home/newsite/public_html
ServerName newsite
ServerAlias newsite
ServerPath /home/newsite/public_html
ServerAdmin david@mainsite.net
  <Directory / >
    Options FollowSymLinks
    AllowOverride [COLOR="Gray"]none[/COLOR]
# That will prevent mod_rewrite from working on newsite
  </Directory>
</VirtualHost>


The only other comment is that your DNS may require that the “addon” domain, newsite, be under the main domain’s physical structure. Okay, if on your server, then probably not.

If on your server, though, you’ll need to do a bit more (DNS-wise) than my httpd-vhosts.conf and hosts file additions (you DID update your server’s hosts file, didn’t you?).

Regards,

DK

Ok, I tried what you suggested. Didn’t work.

I realized that my main sites vhost stuff might have something to do with it. So, here’s my full file.


<VirtualHost serverip:80>
DocumentRoot /home/mainsite/public_html
  ServerAdmin david@mainsite.net
  <Directory />
    Options FollowSymLinks
    AllowOverride All
  </Directory>
  
  ErrorLog /var/log/apache2/error.log
  LogLevel warn
  CustomLog /var/log/apache2/access.log combined
  <Directory "/home/mainsite/public_html">
    allow from all
    Options +Indexes
    RewriteEngine on
    #RewriteBase /fbk/ctb
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteCond %{REQUEST_URI} ^/fbk/ctb/(.*)$
    #RewriteRule ^(.*)$ /fbk/ctb/index.php?q=$1 [L,QSA]
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]    
  </Directory>
ServerName mainsite.net
  
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /home/newsite/public_html
ServerName newsite
ServerAlias newsite
ServerPath /home/newsite/public_html
ServerAdmin david@mainsite.net
  <Directory / >
    Options FollowSymLinks
    AllowOverride none
  </Directory>
</VirtualHost>


DR,

There should be NO / in the ServerName or ServerAlias. In addition, Apache may be looking for a space after the / in the <Directory> line.

Regards,

DK

DR,

For my TEST server (i.e., no .com and I do use an abbreviation of my domains locally):

<VirtualHost 127.0.0.1:80>
ServerName arj
DocumentRoot W:/ARJ
ServerPath W:/ARJ
</VirtualHost>

That’s the minimum required. Of course, I’m using a WinDoze box (locally, for my test server, but 'nix on the production server).

Regards,

DK

Did that. Didn’t change anything. My main site still works fine, but I still can’t get {myserverip}/newuser to go to /home/newuser/public_html