-1

I'm working locally and I always specify files as /files.jpg or whatnot so the server will always know to look at the root level to find the files. That way if I'm on a subpage it won't choke. But locally the files do not show up. My file structure is apache2/htdocs/name_of_folder. name_of_folder is my "root". I then modify my virtualhost file so when I enter localhost/name_of_folder it will show my site. I specify the DocumentRoot so I thought when I say localhost/name_of_folder that is working at the document root?

In httpd-vhosts.conf I have it set to

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/opt/local/apache2/name_of_folder"
    ServerName localhost/name_of_folder
    ServerAlias www.localhost/name_of_folder
    ErrorLog "logs/name_of_folder_log"
    CustomLog "logs/name_of_folder_access_log" common
</VirtualHost>

What am I doing wrong?

rich
  • 139
  • 1
  • 1
  • 4
  • @PeeHaa - I get the following for an image...127.0.0.1 - - [23/Jul/2011:09:48:16 -0400] "GET /rss_28x28.png HTTP/1.1" 404 211 – rich Jul 23 '11 at 13:55

3 Answers3

0

You are misusing the ServerName and ServerAlias directives. They have nothing to do with files or paths. They are the domain name that identifies the web site (together with an optional port if not 80). If you want to move your document root, you have to edit the DocumentRoot directive.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • G. Vicario - But I am using this apache to have multiple sites. So I specify the documentroot to be apache2/htdocs and then inside of htdocs I have the site folders and those are the roots. Can I have multiple documentroots for each site? I thought I could only have one? – rich Jul 23 '11 at 13:55
  • @rich - I'm not sure I follow you. If you want multiple sites, you create multiple `...` blocks. You don't configure everything in a single site. – Álvaro González Jul 23 '11 at 13:59
  • G. Vicario - Right...I understand I would need multiple VirtualHost blocks but the only one I have in there now is not working. Wouldn't me saying DocumentRoot "/opt/local/apache2/name_of_folder" in the virtualhost (see my code above) get it to work? – rich Jul 23 '11 at 14:04
  • @rich - Nope. If `name_of_folder` is the document root, typing `/name_of_folder` in your browser looks for `/opt/local/apache2/name_of_folder/name_of_folder`. – Álvaro González Jul 23 '11 at 14:09
0

You may not do this in that way. The directive ServerName is not supposed to get an URL but a domain name. Set the root to the parent folder, deny all access to it using <Directory> and allow access to you subdirectory to get it work.

marc
  • 6,103
  • 1
  • 28
  • 33
  • in my httpd.conf I have ServerRoot "/opt/local/apache2" and DocumentRoot "/opt/local/apache2/htdocs". And inside of htdocs are directories of site names. So one cold be name_of_folder. I want to then be able to say localhost/name_of_folder and it knows that is the root. Not sure what you mean by setting the root to the parent...I thought I did that by doing the documentroot above. Why would I want to deny access? – rich Jul 23 '11 at 14:00
  • @rich: Apart from concrete directives: What are you exactly trying to archive? – marc Jul 23 '11 at 14:06
  • @marc-Sorry marc not sure what your question means. Locally my images are not showing up because I specify /file.jpg in my html code. It works fine in production.But locally the images just don't show up because I am assuming it is looking for the image in the root because I specified a /.I specified the documentroot to be apache2/htdocs in my httpd.conf file. I did that because I have multiple sites I want to work on. So I guess the file is looking in the htdocs folder for my image and of course it is not there. So I thought a VirtualHost would tell it to change its documentroot for that site – rich Jul 23 '11 at 14:12
  • Yes, but `VirtualHost` only works with domain names and not with paths. So you should choose the subdomain as PeeHaa answered. Then the browser will see the correct root. – marc Jul 23 '11 at 14:30
0

In stead of doing:

ServerName localhost/name_of_folder
ServerAlias www.localhost/name_of_folder

Create a subdomain:

ServerName subdomain.localhost
PeeHaa
  • 71,436
  • 58
  • 190
  • 262
  • is there something else I need to do in order to allow for subdomains? I can't figure it out. I did what you said with subdomain.localhost I also tried subdomain.127.0.0.1 and it keeps redirecting to my isp page not found – rich Jul 23 '11 at 14:36
  • @rich: Have you restarted the apache services? To do this go to: Start -> Run -> and type in services.msc. Find the Apache service and restart it – PeeHaa Jul 23 '11 at 14:46
  • yes I am on a Mac (apachectl graceful). I think it as to do with my host file. I added 127.0.0.1 subdomain.localhost and it now points to the htdocs directory...the second virtualhosts stack...` DocumentRoot "/opt/local/apache2/htdocs/subdomain" ServerName subdomain.localhost ` ` DocumentRoot "/opt/local/apache2/htdocs" ServerName localhost ` It is like it is skipping right over the first virtualhost. Maybe because I have two 127.0.0.1 declared in my hosts? `127.0.0.1 localhost 127.0.0.1 subdomain.localhost` – rich Jul 23 '11 at 15:01