go - 无法创建在线网页
问题描述
我正在尝试创建 Golang 网页...
进步:
- Ubuntu 18.04 安装在本地和 Linode VPS 上。
- 创建并编译了一个本地 Golang “Hello World”脚本,该脚本在本地和在线都可以渲染。
- 创建了一个 net/http Golang 脚本,在本地调用http://localhost:8080/testing时可以正常工作,看看它是否有效
- 将脚本上传到 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) 等的错误和警告吗?
解决方案
使用 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 发行版的常用/预装防火墙指南。
如果您计划投入生产,请有人帮助您确保部署的安全性和可用性。
推荐阅读
- r - xaringan:更改特定块的代码背景
- elasticsearch - 通过消息 logstash 创建一个字段
- linux - 在 Linux x64 上禁用 NX
- reporting-services - CRM - 基于其他行的 SSRS FetchXML 行过滤
- php - 从查询 laravel 计算行数
- here-api - 在选择“选择视图”选项之前,这里的地图不会显示
- java - 允许 Spring Security + Cas Auth + 静态用户列表
- c - 在具有 4 个线程的程序上调用 pthread_cond_signal 时,同一线程获取互斥锁
- python - 使用正则表达式将自由文本解析为 dict
- java - 调用菜单视图时出错