PaaPs
PaaPs

Reputation: 393

apache virtualhost - localhost and development alias/servername

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.

Upvotes: 0

Views: 2755

Answers (2)

Aaron
Aaron

Reputation: 7444

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

Upvotes: 0

Chris Lear
Chris Lear

Reputation: 6742

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.

Upvotes: 1

Related Questions