我正在尝试将我的apache vhosts文件配置为具有localhost / something主机名和“别名”主机名。我目前正在使用google api,并且它们不接受自定义别名作为url,因此无法使其与我的自定义url一起使用。有什么想法怎么办?我当前的配置不起作用:
<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>
当我尝试访问127.0.0.1/go或localhost / go时,出现内部服务器错误。
答案 0 :(得分:1)
也许您想要的就是这样
<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>
然后使用http://localhost/go之类的网址来查看网站。
答案 1 :(得分:0)
取决于您的OS /浏览器,您也许可以将开发子域添加到localhost。例如
<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>
然后我将浏览器指向dev1.localhost,然后将其解析为dev1,同样将dev2.localhost和localhost本身也解析为默认的Apache页面。
这解决了我的类似问题。在Debian WSL中的Apache上进行了测试。在Windows Chrome上工作,在Windows Firefox上失败。基于此SO:https://stackoverflow.com/a/35124491