【问题标题】:Yaws server started on localhost of Azure but not accessed from cloudapp.netYaws 服务器在 Azure 的 localhost 上启动,但未从 cloudapp.net 访问
【发布时间】:2016-01-21 10:33:51
【问题描述】:

我在 Windows Azure VM 上成功启动了 Yaws 服务器,但我无法访问公共域。

目前,我只想使用 Yaws 来托管我的静态内容。

我搜索了一些文章,但没有找到解决方案。

这里是详细的,请给我一些想法,谢谢。

我在 localhost:8000 上启动了 Yaws 服务器

我已经通过以下conf启动了Yaws服务器:

# /etc/yaws/conf.d/localhost.conf

<server localhost>
    port = 8000
    listen = 127.0.0.1
    docroot = /home/me/website
    # dir_listings = true
</server>

我认为我成功启动了http服务器,因为我可以通过curlindex.html的内容:

curl losthost:8000

我在 Windows Azure VM 中绑定端点

我还在 Window Azure VM (Ubuntu Server 15.04) 上设置了端点:

NAME | PROTOCOL | PUBLIC PORT | PRIVATE PORT
:----|:---------|:------------|:-------------
HTTP | TCP      | 80          | 8000

但无法访问azeure_vm_name.cloudapp.net

但我无法通过azure_vm_name.cloudapp.net 访问静态网站。

cloudapp.net 是 Windows Azure VM 的公共域。

但是我可以启动python服务器访问公共域

之前,我尝试在文件夹 /home/me/website 中启动 python http.server:

# python 3
python -m http.server
# python 2
python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...

来自 Yaws 服务器的信息报告

$ sudo yaws -i
Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-
poll:true]

Eshell V6.2  (abort with ^G)
1>
=INFO REPORT==== 22-Oct-2015::07:30:46 ===
Yaws: Using config file /etc/yaws/yaws.conf

=INFO REPORT==== 22-Oct-2015::07:30:46 ===
Yaws: Using subconfig file /etc/yaws/conf.d/localhost.conf

=INFO REPORT==== 22-Oct-2015::07:30:48 ===
yaws debug:Add path "/usr/lib/yaws/custom/ebin"

=INFO REPORT==== 22-Oct-2015::07:30:48 ===
yaws debug:Add path "/usr/lib/yaws/examples/ebin"

=INFO REPORT==== 22-Oct-2015::07:30:48 ===
yaws debug:Running with id="default" (localinstall=false)
Running with debug checks turned on (slower server)
Logging to directory "/var/log/yaws"

=INFO REPORT==== 22-Oct-2015::07:30:48 ===
Ctlfile : /home/me/.yaws/yaws/default/CTL

=INFO REPORT==== 22-Oct-2015::07:30:48 ===
Yaws: Listening to 127.0.0.1:8000 for <1> virtual servers:
 - http://localhost:8000 under /home/me/website

参考文献

Installing Yaws server on Ubuntu 12.04 (Using a cloud service)

https://askubuntu.com/q/190841/249957

【问题讨论】:

  • 我怀疑 Yaws 正在丢弃您的请求,因为您请求中的服务器名称与其配置的任何服务器都不匹配。检查/var/log/yaws 下的日志以查看它们是否显示任何错误。您也可以考虑运行sudo yaws -i --debug,这可能会为您提供更多信息。

标签: azure erlang httpserver yaws


【解决方案1】:

经过一番研究和测试,我终于找到了解决办法。

最终解决方案

这是最后的yaws.conf

<server azure_VM_name.cloudapp.net>
    port = 8000
    listen = <Azure VM INTERNAL IP ADDRESS>
    docroot = /home/scotv/repo/shanlin-web
    # dir_listings = true
</server>

如何找到这个解决方案

感谢@steve-vinoski 的建议,我打开--debug开关,阅读官方文档《Yaws - Yet Another Web Server (Oct 7, 2015 version)》。

在第 9 页,Yaws PDF 文档提到:

示例 2.1 中的配置在地址 127.0.0.1:8000 上定义了一个名为“localhost”的 HTTP 服务器。 了解服务器的名称和地址之间的区别很重要。 名字是 客户端 HTTP 主机中的预期值:标头。这通常与完全限定的 DNS 名称 相同 服务器的 IP 地址,而 地址是服务器的实际 IP 地址。

所以我在浏览器中检查了 HTTP 请求标头:

GET / HTTP/1.1
Host: azure_VM_name.cloudapp.net
Connection: keep-alive

这就是为什么我将yaws.conf 改为:

# <server localhost> </server>
<server azure_VM_name.cloudapp.net> </server>

根据SimpleHTTPServer的消息,下一步是找出我需要监听的IP:

python -m SmpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...

我决定听0.0.0.0

它有效,我现在可以访问 azure_VM_name.cloudapp.net。

但是,yaws.conf 的手册中提到:

服务器部分

听 = IpAddress

如果指定的 IP 地址是 0.0.0.0,Yaws 将监听指定端口上的所有本地 IP 地址

我不想全听。

所以我检查了 Windows Azure VM 提供的 IP 地址,我们有:

DNS NAME
azrue_VM_name.cloudapp.net
HOST NAME
azrue_VM_name
PUBLIC VIRTUAL IP (VIP) ADDRESS
40.*.*.*
INTERNAL IP ADDRESS
100.*.*.*

尝试了PUBLIC VIP和INTERNAL IP,最后发现应该在INTERNAL IP:8000上收听。

所以现在,我正在运行yaws

sudo yaws -D --heart --debug --conf ./deploy/yaws.conf

【讨论】:

  • 如果您现在对它的运行方式感到满意,您可以关闭--debug
猜你喜欢
  • 1970-01-01
  • 2017-03-02
  • 1970-01-01
  • 2021-08-29
  • 2017-07-04
  • 2023-03-29
  • 1970-01-01
  • 2017-03-20
  • 1970-01-01
相关资源
最近更新 更多