apache 虚拟主机 - 本地主机和开发 alias/servername
apache virtualhost - localhost and development alias/servername
我正在尝试将我的 apache vhosts 文件配置为具有 localhost/something 主机名和 "alias" 主机名。我目前正在使用 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 时出现内部服务器错误。
也许你想要的是这样的
<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>
然后使用 url 点赞 http://localhost/go 来查看网站。
根据您的 OS/browser,您或许能够向本地主机添加开发子域。例如
<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:
我正在尝试将我的 apache vhosts 文件配置为具有 localhost/something 主机名和 "alias" 主机名。我目前正在使用 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 时出现内部服务器错误。
也许你想要的是这样的
<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>
然后使用 url 点赞 http://localhost/go 来查看网站。
根据您的 OS/browser,您或许能够向本地主机添加开发子域。例如
<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: