2

I want to host a webpage for 150 users. Each user will have a unique webpage by the url url/username/index.html. Here username is unique for all users rest all remains common.

So do I need to make 150 virtual hosts in Apache Server or is there some other way out?

2
  • 1
    Is url something like http://example.com or something like http://example.com/path/to/userdirs?
    – Freddy
    May 2, 2020 at 11:51
  • url is something like http://example.com/username/index/html where username will vary for different users May 2, 2020 at 14:03

2 Answers 2

2

You could enable per-user web directories with mod_userdir which maps

http://example.com/~username/index.html

to the corresponding file

/home/username/public_html/index.html

in the user directory per default.

To get rid of the tilde, you could use Apache's rewrite engine and forbid access to all URLs starting with ~ and use Aliases to map the individual paths to their user directories.

Add this to your VirtualHost config:

RewriteEngine On
# forbid URLs starting with /~
RewriteRule ^/~  -  [F]

# map individual paths to user dirs
Alias /bart    /home/bart/public_html
Alias /homer   /home/homer/public_html
Alias /lisa    /home/lisa/public_html
Alias /maggie  /home/maggie/public_html
# ...

If you don't need to serve any files from your DocumentRoot, you could use one AliasMatch instead of 150 Aliases:

# map all paths to user dirs
AliasMatch ^/([^/]+)(/.*)?$  /home/$1/public_html$2

You need to enable mod_userdir and mod_rewrite in your server, on Debian you would do this with a2enmod and a restart.

sudo a2enmod userdir rewrite
sudo service apache2 restart
0

This cannot even be done with virtual hosts because you would need different host names (or ports) for telling them apart.

This is just one host with subdirectories for different users. So you may have to (or at least want) to set different file permissions for each of those subdirectories.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .