gpt4 book ai didi

php - 如何从互联网访问虚拟主机?

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:44 25 4
gpt4 key购买 nike

我想通过互联网上的虚拟主机访问我的网站。现在,我使用服务器的公共(public) IP 地址访问我的网站。这是我正在使用的(请参见下文)。

http://122.4.195.12:7777/site/index.php

  1. 有没有办法从互联网访问我的虚拟主机?当我从我的互联网 ( https://mysite/site/index.php ) 访问我的虚拟主机时,我得到了

DNS_PROBE_FINISHED_NXDOMAIN error
mysite’s server IP address could not be found.

  1. 有没有办法在通过公共(public) IP 地址访问我的网站时添加 SSL?当我将 http 更改为 https 时,我得到了

ERR_SSL_PROTOCOL_ERROR
122.4.195.12 sent an invalid response.
http://122.4.195.12:7777/site/index.php -> https://122.4.195.12:7777/site/index.php

这是我的虚拟主机配置:

<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>

这是我服务器的主机文件:

127.0.0.1       mysite

最佳答案

对于问题1

更简单的方法仍然是注册一个域名,将其指向您的 IP 地址,并为其设置您的 VirtualHost ServerName

VirtualHost 实际上检测来自服务器站点的 Host HTTP header ,所以这里的关键是:

How to make the client browser send the Host header the same with you defined on server

例如,通过使用 CURL,您可以强制它使用用户定义的 Host header ,如下所示:curl -H 'Host: mysite' 122.4.195.12:7777/site/index .php

如果您使用的是 Chrome,您可以尝试使用浏览器扩展程序,例如 this

对于问题2

您在 Apache 配置中在端口 443 而不是 7777 上启用了 HTTPS

这意味着您应该像这样访问您的 HTTPS 服务 https://122.4.195.12:443/site/index.php 而不是 https://122.4.195.12:7777/site/index.php

关于php - 如何从互联网访问虚拟主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56141397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com