如何从互联网访问虚拟主机? [英] How to access virtual host from the internet?
问题描述
我想通过互联网上的虚拟主机访问我的网站.现在,我正在使用服务器的公共IP地址访问我的网站.这是我正在使用的(请参见下文).
I want to access my website via virtual host from the internet. For now, I am using the public IP address of my server to access my website. Here is what I am using (please see below).
- 是否可以通过互联网访问我的虚拟主机?当我从互联网访问虚拟主机时( https://mysite/site/index.php )我正在
DNS_PROBE_FINISHED_NXDOMAIN错误
找不到mysite的服务器IP地址.
DNS_PROBE_FINISHED_NXDOMAIN error
mysite’s server IP address could not be found.
- 通过公用IP地址访问我的网站时,是否可以添加SSL?当我将http更改为https时,我得到了
ERR_SSL_PROTOCOL_ERROR
122.4.195.12发送了无效的响应.
http://122.4.195.12:7777/site/index.php -> https://122.4.195.12:7777/site/index.php
这是我的虚拟主机配置:
Here is my Virtual Host Config:
<VirtualHost *:7777>
DocumentRoot "C:\xampp\htdocs"
ServerName mysite
<Directory "C:\xampp\htdocs">
Require all granted
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "C:/xampp/htdocs"
ServerName mysite
SSLEngine on
SSLCertificateFile "crt/scratchitsite/server.crt"
SSLCertificateKeyFile "crt/mysite/server.key"
<Directory "C:\xampp\htdocs">
Require all granted
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
这是我的服务器的主机文件:
Here is the host file of my server:
127.0.0.1 mysite
推荐答案
问题1
更简单的方法仍然是注册域名,将其指向您的IP地址,并为其设置VirtualHost ServerName
The easier way will still be registering a domain name, point it to your IP address, and setup your VirtualHost ServerName for it
VirtualHost实际上从服务器站点检测到 Host
HTTP标头,所以这里的关键是:
The VirtualHost actually detecting the Host
HTTP Header from server site, so the key thing here is:
如何使客户端浏览器发送与您在服务器上定义的相同的
Host
标头
例如,通过使用CURL,您可以强制其使用用户定义的 Host
标头,如下所示: curl -H'Host:mysite'122.4.195.12:7777/site/index.php
For example, by using CURL you can force it to use the user definied Host
header like this: curl -H 'Host: mysite' 122.4.195.12:7777/site/index.php
如果您使用的是Chrome,则可以尝试使用浏览器扩展程序,例如
If you're using Chrome, you can try to use a browser extension, like this
问题2
您已在Apache配置中在端口443而不是7777上启用了HTTPS
You've enabled HTTPS on port 443 instead of 7777 in your Apache configuration
这意味着您应该像这样 https://122.4.195.12:443/site/index.php
那样访问HTTPS服务,而不是此 https://122.4.195.12:7777/site/index.php
Which means you should access your HTTPS service like this https://122.4.195.12:443/site/index.php
instead of this https://122.4.195.12:7777/site/index.php
这篇关于如何从互联网访问虚拟主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!