0

I'm working on image hosting imgur clone. I created a subdomain for my images i.localhost Added to the hosts file -> 127.0.0.1 i.localhost Added to httpd-vhosts.conf ->

<VirtualHost *:80>
   DocumentRoot "/Users/BillGates/Sites/images/"
   ServerName i.localhost
</VirtualHost>

My site is running on my local machine at localhost. Visitor can see the image at url like localhost/NE2bd, I did this url with Mod_Rewrite so it's all like imgur.com

Since I store all my images in /Users/BillGates/Sites/images/ I can't see an image at i.localhost/NE2bd.jpeg !!!! But the image is in the images folder!!

I am getting Not Found

The requested URL /NE2bd.jpeg was not found on this server. My httpd-vhosts.conf

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

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

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/usr/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot "/Users/BillGates/Sites/images/"
   ServerName i.localhost
</VirtualHost>

And of course some important lines in httpd.conf

DocumentRoot "/Users/BillGates/Sites"

user9517
  • 114,104
  • 20
  • 206
  • 289
Sharky
  • 3
  • 2

2 Answers2

0

Looks like you are using Apache 2 on OSX, and that the file that you are editing is /etc/apache2/extra/httpd-vhosts.conf. Some of the code that you have copied and pasted appears to be missing <VirtualHost *:80>

Perhaps the configuration that you have added to is not being read into the apache configuration. By default this file is not read in. You could try editing the main /etc/apache2/httpd.conf to include this file.

Try uncommenting the line:

Include /private/etc/apache2/extra/httpd-vhosts.conf.

And of course remember to start and stop apache for it to take effect.

nickgrim
  • 4,336
  • 1
  • 17
  • 27
digitalsean
  • 116
  • 1
  • The OPs formatting was incorrect – user9517 Sep 20 '11 at 14:09
  • nickgrim, yes I forgot to uncomment the line including httpd-vhosts – Sharky Sep 20 '11 at 15:32
  • Now, When I go to localhost I get the index (list od images) of Sites/images – Sharky Sep 20 '11 at 15:48
  • Assuming that you mean that when you go to i.localhost you see a list of all the images, and that you don't want to show the list of files by default, perhaps you could try adding an index.html or similar default file to the folder Sites/images – digitalsean Oct 03 '11 at 09:09
0

Your configuration looks wrong. I am used to declare a vhost like

<VirtualHost *:80>
ServerAdmin webmaster@host.foo.com
DocumentRoot /www/docs/host.foo.com
ServerName host.foo.com
</VirtualHost>

in a file which gets included in your httpd.conf.

I am not sure if your configuration is even used by Apache, because your "localhost"-vhost doesn't exist in your configuration.

Try to add the domains "foo.bar" and "i.foo.bar" in your /etc/hosts and point them to your IP. Then write a VirtualHost directive for each of them with different DocumentRoot's.

After that, try to reach the files located in the directories with your (sub-)domain and post errors (and configs).

Subito
  • 378
  • 1
  • 3
  • 11