首页 > 解决方案 > 无法创建在线网页

问题描述

我正在尝试创建 Golang 网页...

进步:

  1. Ubuntu 18.04 安装在本地和 Linode VPS 上。
  2. 创建并编译了一个本地 Golang “Hello World”脚本,该脚本在本地和在线都可以渲染。
  3. 创建了一个 net/http Golang 脚本,在本地调用http://localhost:8080/testing时可以正常工作,看看它是否有效
  4. 将脚本上传到 Linode 服务器并显示初始状态消息,但是当调用 http:123.456.789.32:8080/testing 以查看它是否有效时,浏览器会冻结。
//
// Golang - main.go
//
package main

import (
  "net/http"
)

func sayHello(w http.ResponseWriter, r *http.Request) {
  message := r.URL.Path
  message = "Hello " + message

  w.Write([]byte(message))
}

func main() {
  http.HandleFunc("/", sayHello)

  if err := http.ListenAndServe(":8080", nil); err != nil {
    panic(err)
  }
}

没有呈现错误或警告,也无法找到任何日志引用。

可以记录或呈现类似于 PHP error_reporting(-1)、declare(strict_types=1) 等的错误和警告吗?

标签: go

解决方案


使用 Nmap 快速检查显示了以下结果:

nmap -sV -p 8080 <yourIP>
Starting Nmap 7.70 ( https://nmap.org ) at 2019-07-04 07:45 CEST
Nmap scan report for <your-domain>.com (<yourIP>)
Host is up (0.032s latency).

PORT     STATE    SERVICE    VERSION
8080/tcp filtered http-proxy

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.90 seconds

“已过滤”状态实际上意味着该端口上没有响应,而不是完全拒绝请求。

检查 的输出iptables -L -n。假设您有一个防火墙正在运行并阻止端口 8080。不要简单地停用防火墙,而是阅读如何在您正在使用的防火墙产品中打开端口 8080。Linode 有各种 Linux 发行版的常用/预装防火墙指南

如果您计划投入生产,有人帮助您确保部署的安全性和可用性。


推荐阅读