ssh tunnel to port 80 + vhosts + serveralias + virtualdocumentroot not working

I have a remote server with all ports disabled except 22 (ssh). I use Putty to connect to the server with a forwarded port (Source port: 8080 Destination: *.*.*.*:80). When I open a browser and put localhost:8080 in I get the appropriate webpage.

Now I want to have subdomain virtual hosts like this: subdomain.localhost:8080. Subdomain being the name of a folder.

I've tried this:

<VirtualHost *:80>
        UseCanonicalName On
        ServerAlias *
        VirtualDocumentRoot /var/www/%1
        <Directory />
                Options FollowSymLinks
                AllowOverride All

Open in new window

When I try to access "localhost:8080" with "UseCanonicalName On" in chrome it returns "NOT FOUND Apache/2.2.16 (Debian) Server at Port 80" (I figured out it tries to find an index in "sub" folder)

When it's "UseCanonicalName Off" it returns "NOT FOUND Apache/2.2.16 (Debian) Server at localhost Port 8080".  (tries to find an index in "localhost" folder).

In both cases when I try to access "sub.localhost:8080" chrome returns ERR_NAME_NOT_RESOLVED.

They seem to be separate issues. In first two cases no matter what I try it never registers ServerAlias. In the third one it doesn't seem to even make it to the server.

Can you help me with this?
Who is Participating?
Steve BinkCommented:
You can modify your hosts file to provide resolution for the subdomain: sub.localhost

Open in new window

The hosts file is found in /etc on *nix, and in %WINDIR%\system32\drivers\etc on Windows.
CarboneczAuthor Commented:
I've just found out that you can use for localhost subdomains.

"" instead of "sub.localhost:8080".

This seems to solve all issues. I don't like to rely on this website though. Is there a better solution?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.