我已经设置了一个简单的服务器来测试我的 TLS 证书,TLS 部分工作正常。我通过 CloudFlare 获得了我的 DNS。
我希望该网站保持匿名,因此我将域更改为“example.com”。
这是简单服务器的代码:
package main
import (
"log"
"net/http"
)
var hostname = "example.com"
var key = "/srv/ssl/" + hostname + "-2017.03.20.key"
var cert = "/srv/ssl/ssl-bundle.crt"
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("TLS test"))
})
// go serveHTTP()
// go redirectHTTP()
serveHTTPS()
}
func serveHTTP() {
if err := http.ListenAndServe(":80", nil); err != nil {
log.Fatalf("ListenAndServe error: %v", err)
}
}
func redirectHTTP() {
err := http.ListenAndServe(":80", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "https://"+hostname+r.RequestURI, http.StatusMovedPermanently)
}))
if err != nil {
log.Fatalf("ListenAndServe error: %v", err)
}
}
func serveHTTPS() {
log.Fatal(http.ListenAndServeTLS(":443", cert, key, nil))
}
现在如果我像这样运行服务器,然后转到 https://example.com 那么它就不起作用了。
但是如果我将允许我提供 HTTP 服务的部分更改为:
go serveHTTP()
// go redirectHTTP()
serveHTTPS()
然后 HTTP 和 HTTPS 突然都可以工作了。因此,如果我通过输入 http://example.com 和 https://example.com 访问我的网站,两者都可以正常工作。
如果我注释掉 go serveHTTP() 并尝试像这样将 HTTP 重定向到 HTTPS:
// go serveHTTP()
go redirectHTTP()
serveHTTPS()
然后我在屏幕上看到这个:
如果我改回这个:
// go serveHTTP()
// go redirectHTTP()
serveHTTPS()
并且不是通过域名访问页面,而是通过ip地址访问页面,我当然会收到警告,因为证书不是颁发给ip地址,而是我使用的域名。
如果我坚持点击高级并添加异常,那么它就可以工作了。
所以实际上它是在端口 443 上提供服务的,但是尝试通过域名访问页面,让它通过 CloudFlare DNS,然后它就不起作用了。
即使我只将 CloudFlare 用作“仅 DNS”,也没有关系:
或者如果我换成proxy,还是一样:
我已关闭缓存并使用开发人员模式,以便我应该从我的服务器获得“实时响应”。
总而言之,由于我通过 CloudFlare 拥有我的 DNS,CloudFlare 不允许我在没有 HTTP 的情况下提供 HTTPS。我需要没有 HTTP 重定向的 HTTP 和 HTTPS。这真的很奇怪,我不知道如何解决这个问题。服务器通过 443 提供服务,因为正如我所展示的,如果我尝试通过 IP 地址访问该页面并添加安全异常(exception),该页面实际上正在提供服务。
我能做什么?
最佳答案
当 Cloudflare 设置为灵活 SSL 模式时,the connection to the origin will always be over HTTP (不是 HTTPS)。
来自 Cloudflare 知识库:
You don't need to have an SSL certificate on your web server, but your visitors still see the site as being HTTPS enabled. This option is not recommended if you have any sensitive information on your website. This setting will only work for port 443->80, not for the other ports we support like 2053. It should only be used as a last resort if you are not able to setup SSL on your own web server, but it is less secure than any other option (even “Off”), and could even cause you trouble when you decide to switch away from it: How do I fix the infinite redirect loop...
要更改此设置,请转到 Cloudflare 仪表板中的“加密”选项卡,然后在 SSL 选项中将“灵活”更改为“完全(严格)”(如果您使用的是自签名证书,则更改为“完全”) .
关于go - CloudFlare 不会让我只提供 HTTPS,它只有在我同时提供 HTTP 和 HTTPS 时才有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42894944/
设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案
是的,我知道最好使用webmock,但我想知道如何在RSpec中模拟此方法:defmethod_to_testurl=URI.parseurireq=Net::HTTP::Post.newurl.pathres=Net::HTTP.start(url.host,url.port)do|http|http.requestreq,foo:1endresend这是RSpec:let(:uri){'http://example.com'}specify'HTTPcall'dohttp=mock:httpNet::HTTP.stub!(:start).and_yieldhttphttp.shou
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
Rails中有没有一种方法可以提取与路由关联的HTTP动词?例如,给定这样的路线:将“users”匹配到:“users#show”,通过:[:get,:post]我能实现这样的目标吗?users_path.respond_to?(:get)(显然#respond_to不是正确的方法)我最接近的是通过执行以下操作,但它似乎并不令人满意。Rails.application.routes.routes.named_routes["users"].constraints[:request_method]#=>/^GET$/对于上下文,我有一个设置cookie然后执行redirect_to:ba
我正在使用Heroku(heroku.com)来部署我的Rails应用程序,并且正在构建一个iPhone客户端来与之交互。我的目的是将手机的唯一设备标识符作为HTTPheader传递给应用程序以进行身份验证。当我在本地测试时,我的header通过得很好,但在Heroku上它似乎去掉了我的自定义header。我用ruby脚本验证:url=URI.parse('http://#{myapp}.heroku.com/')#url=URI.parse('http://localhost:3000/')req=Net::HTTP::Post.new(url.path)#boguspara
我试图在我的网站上实现使用Facebook登录功能,但在尝试从Facebook取回访问token时遇到障碍。这是我的代码:ifparams[:error_reason]=="user_denied"thenflash[:error]="TologinwithFacebook,youmustclick'Allow'toletthesiteaccessyourinformation"redirect_to:loginelsifparams[:code]thentoken_uri=URI.parse("https://graph.facebook.com/oauth/access_token
我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的
我是Ruby的新手。我试过查看在线文档,但没有找到任何有效的方法。我想在以下HTTP请求botget_response()和get()中包含一个用户代理。有人可以指出我正确的方向吗?#PreliminarycheckthatProggitisupcheck=Net::HTTP.get_response(URI.parse(proggit_url))ifcheck.code!="200"puts"ErrorcontactingProggit"returnend#Attempttogetthejsonresponse=Net::HTTP.get(URI.parse(proggit_url)