0

I'm trying to configure my apache vhosts file to have a localhost/something hostname and "alias" hostnames. I'm working with google api's currenctly and they are not accepting custom aliases as url's, so I can't make it work with my custom url's. Any thoughts of what to do? My current config that's not working:

<VirtualHost 127.0.0.1:80>
    ServerName localhost/go
    ServerAlias localhost/go
    DocumentRoot "D:/username/Web/server.dev/go"
</VirtualHost>

<Directory "D:/username/Web/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order Deny,Allow
        Allow from all
        Require all granted
</Directory>

<VirtualHost *:80>
    ServerName api.server.dev
    ServerAlias api.server.dev
    DocumentRoot "D:/username/Web/server.dev/api"
</VirtualHost>

##... more custom urls with subdomains cut out because it's unnecessary

<VirtualHost *:80>
    ServerName adstrck.server.dev
    DocumentRoot "D:/username/Web/server.dev/adstrck"
</VirtualHost>

### ALL OTHERS ###

<VirtualHost *:80>
    ServerName www.server.dev
    ServerAlias server.dev *.server.dev
    DocumentRoot D:/username/Web/server.dev
</VirtualHost>

When I'm trying to access 127.0.0.1/go or localhost/go I get an internal server error.

PaaPs
  • 373
  • 1
  • 4
  • 18
  • A serverName is an IP address or hostname, not a path. See https://httpd.apache.org/docs/2.4/mod/core.html#servername. You can't put `/` in a hostname. – Chris Lear Sep 10 '18 at 13:29
  • sorry, where do I specify the hostname? You mean ServerName? – PaaPs Sep 10 '18 at 13:37
  • Yes, ServerName has to be an IP address or hostname. – Chris Lear Sep 10 '18 at 13:38
  • ok. That does not help with the issue – PaaPs Sep 10 '18 at 13:42
  • Is the issue that you are getting an internal server error? Can you find the text of the error and share it here? (It will be in a server error log almost certainly) – Chris Lear Sep 10 '18 at 13:47
  • [Mon Sep 10 16:56:31.401340 2018] [core:error] [pid 10324:tid 1996] [client 127.0.0.1:61779] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://127.0.0.1/go/ – PaaPs Sep 10 '18 at 13:57
  • basically a redirect loop – PaaPs Sep 10 '18 at 13:58

2 Answers2

1

Maybe what you want is something like this

<VirtualHost 127.0.0.1:80>
    ServerName localhost
    ServerAlias server.dev *.server.dev
    DocumentRoot "D:/username/Web/server.dev"
</VirtualHost>

<Directory "D:/username/Web/server.dev">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order Deny,Allow
        Allow from all
        Require all granted
</Directory>

Then use a url like http://localhost/go to view the site.

Chris Lear
  • 6,592
  • 1
  • 18
  • 26
  • does not help here. I want BOTH localhost, and serveralias like server.dev – PaaPs Sep 10 '18 at 14:14
  • Ok, there was a type in your example, i did not recheck the documentroot, it was missing a comma. This did work, thank you. (although it works only as 127.0.0.1, but still.. :)) – PaaPs Sep 10 '18 at 14:26
  • 1
    Sorry about the typo. I've fixed it. – Chris Lear Sep 10 '18 at 14:33
  • I've also added a `ServerAlias` line, which should make `http://server.dev/go` work (assuming `server.dev` resolves to `127.0.0.1`) – Chris Lear Sep 10 '18 at 14:36
0

Depending on your OS/browser, you may be able to add a development subdomain to localhost. E.g.

<VirtualHost *:80>
  ServerName dev1.localhost
  ## rest of your config
  ## e.g. ServerAlias my.website.on.the.internet.com
  DocumentRoot /var/www/dev1
</VirtualHost>

<VirtualHost *:80>
  ServerName dev2.localhost
  DocumentRoot /var/www/dev2
</VirtualHost>

# Default / catch-all
<VirtualHost *:80>
  DocumentRoot /var/www/html
</VirtualHost>

I then pointed my browser to dev1.localhost and that resolved to dev1 and likewise for dev2.localhost and localhost by itself resolved to the default apache page.

This resolved my similar problem. Tested on Apache in a Debian WSL. Worked on Windows Chrome, failed on Windows Firefox. Based on this SO: https://stackoverflow.com/a/35124491

Aaron
  • 7,015
  • 2
  • 13
  • 22