-1

I have multiple virtual host in one server and plan to has some alias setup in one virtualhost.

So I add the

Alias /foo/ /path/to/foo/

in virtualhost directive,but it has no effect. Request of host1/foo/ will return 404. But if I add this to /etc/apache2/mods-available/alias.conf, it works. But the problem is host2 will also share this alias.

Is there a way to make the alias work only for host1?

BTW, I use apache2ctl -l, there's no mod_alias.c listed, weird.

Giacomo1968
  • 3,542
  • 27
  • 38
0x7c00
  • 1
  • 1
  • 1
    can you post your alias.conf and apache2.conf/httpd.conf and log file to pastie.org? – vsltd Apr 13 '11 at 07:58
  • what os you are running on? – coding Bott Apr 13 '11 at 12:00
  • Is `/path/to/foo/` an empty directory? If there's no `index.html` file there (or whatever your `DirectoryIndex` directive is set to) then a 404 is the correct response. Try putting a file in that directory and then requesting it with something like `http://host1/foo/file.html`. – Ladadadada Nov 09 '13 at 18:38

3 Answers3

0

This worked for me:

Alias /test /tmp/test

Notice that no shashes at the end of paths. But I don't know the reason of this effect.

HUB
  • 6,630
  • 3
  • 23
  • 22
  • that's the exact one i use at first, but unfortunately it doesn't work. and then i add slash, make a request with host1/test/, still 404. Is your apache's configuration layout also the split version(apache2.conf, mod-enable, mod-available, conf.d,etc)? I know this works for the traditional monolithic configuration such as httpd.conf. – 0x7c00 Apr 13 '11 at 08:00
  • Have a look if a file "alias.load" is linked. "alias.conf" doesn't load the module. – HUB Apr 13 '11 at 08:03
  • the only line in alias.load is: LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so. Given it works if the Alias is put in the alias.conf, i guess the mod_alias is already loaded. – 0x7c00 Apr 13 '11 at 08:05
  • It's OK. And does it have a link in enabled directory? – HUB Apr 13 '11 at 08:06
  • yep :( /****for post length limit***/ – 0x7c00 Apr 13 '11 at 08:08
  • Stange... Try to increase LogLevel in your apache2.conf and examine the logs. Or even show them? – HUB Apr 13 '11 at 08:15
  • I remove and purge the apache2 and then reinstall it. Now it works...seems original apache2 is broken. thanks for the reply. – 0x7c00 Apr 14 '11 at 03:50
  • That's strange... But I'm glad this helped you. – HUB Apr 14 '11 at 10:38
0

The folder /etc/apache2/mods-available/ shows available modules, not installed/enabled ones. this means mod_alias is NOT enabled on your machine.

maybe there is a folder like mods-enabled. create with that folder a link to the file /etc/apache2/mods-available/alias.conf. after that reload/restart the webserver.

next is wrong (see comments): apache2ctl -l should show the module.

run "httpd -M" to see the current loaded modules -> httpd command reference

maybe this command doesnt work on your os. every distribution is a bit different. on gentoo use: "apache2ctl modules"

Giacomo1968
  • 3,542
  • 27
  • 38
coding Bott
  • 568
  • 1
  • 4
  • 13
  • there is alias.conf in mod-enabled, and it's a softlink to mod-available. but apache2ctl -l still didn't show. most of the web's tutorial about alias(and other module load configure) is too old (didn't have the split configuration file layout mentioned) – 0x7c00 Apr 13 '11 at 07:56
  • 1
    Your answer seems to be reasonable. But when I run apache2ctl -l, I get: root@host:~# apache2ctl -l Compiled in modules: So this shows only "compiled in" modules And of course, "alias.load" also requres linking.(on Debian system) – HUB Apr 13 '11 at 07:58
0
BTW, I use apache2ctl -l, there's no mod_alias.c listed, weird.

Then that is your problem. If mod_alias is not installed, your alias directive will fail. Have that setup & installed & all should work as expected.

Giacomo1968
  • 3,542
  • 27
  • 38
  • The `-l` option only lists modules that were *compiled* into Apache. Modules can still be *loaded* separately. You can list these with the `-M` option. – Ladadadada Nov 09 '13 at 18:32
  • Indeed, but if that is the case, the issue of it still not being loaded is in question since that `alias` directive clearly should work. – Giacomo1968 Nov 09 '13 at 18:43