简体   繁体   English

带有快速和端口转发的 greenlock (lets'encrypt)

[英]greenlock (lets'encrypt) with express and port forwarding

I am trying to set up letsencrypt (now greenlock apparently) for port forwarding with express.我正在尝试设置letsencrypt(现在显然是greenlock)以使用express进行端口转发。

I had this first issue that I solved with:我解决了第一个问题

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 3443

The issue is that, now, I get:问题是,现在,我得到:

Fetching certificate for 'xxx' to use as default for HTTPS server...
[acme-v2] handled(?) rejection as errback:
Error: connect ECONNREFUSED 127.0.1.1:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1126:14)
Error loading/registering certificate for 'xxx':
Error: connect ECONNREFUSED 127.0.1.1:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1126:14) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.1.1',
  port: 80
}

My app is like that right now:我的应用程序现在是这样的:

require("greenlock-express")
    .create({
    server: "https://acme-staging-v02.api.letsencrypt.org/directory",
        email: "xxx@gmail.com", // The email address of the ACME user / hosting provider
        agreeTos: true, // You must accept the ToS as the host which handles the certs
        configDir: "~/.config/acme/", // Writable directory where certs will be saved
        communityMember: true, // Join the community to get notified of important updates
        telemetry: true, // Contribute telemetry data to the projec
    store: require('greenlock-store-fs'),
    approveDomains: ['xxx.xxx.xxx'],
        // Using your express app:
        // simply export it as-is, then include it here
        app: require("../app.js")

        //, debug: true
    })
    .listen(3000, 3443);

Apparently I cannot use ports 80 and 443 with nodeJS, but I cannot either use any other port with greenlock... What is the workaround?显然我不能将端口 80 和 443 与 nodeJS 一起使用,但我也不能将任何其他端口与 greenlock 一起使用......解决方法是什么?

I'm the author of Greenlock.我是Greenlock的作者。

Let's Encrypt vs Greenlock Let's Encrypt vs Greenlock

Let's Encrypt is a brand name of the EFF for their Free SSL service. Let's Encrypt 是 EFF 的免费 SSL 服务的品牌名称。

Greenlock is the brand name I use for my JavaScript client to their service. Greenlock 是我为我的 JavaScript 客户提供服务的品牌名称。

I changed the name when they began pursuing a trademark for Let's Encrypt.当他们开始为 Let's Encrypt 申请商标时,我更改了名称。

Video Tuts视频图

If you follow the Greenlock QuickStart, you cannot fail.如果您遵循 Greenlock 快速入门,您就不会失败。 :) :)

Also, an oldie, but a goodie:此外,一个老歌,但一个好人:

Keep It Stupid-Simple保持愚蠢-简单

  • VPS虚拟主机
  • netcap网帽
  • systemd系统

On a normal VPS (such as Digital Ocean , Linode , Vultr , or Scaleway ), where the disk is persistent, use "netcap".在磁盘持久的普通 VPS(例如Digital OceanLinodeVultrScaleway )上,使用“netcap”。 This will allow a non-root user to bind to privileged ports:这将允许非 root 用户绑定到特权端口:

sudo setcap 'cap_net_bind_service=+ep' $(which node)

TADA!多田! Now you can run node./server.js --port 80 as a normal user!现在您可以以普通用户身份运行node./server.js --port 80了!

Aside :旁白

You can also use systemd to stop and start your service.您还可以使用systemd来停止和启动您的服务。 Since systemd is sometimes a pita, I wrote a wrapper script in Go that makes it really easy to deploy node projects:由于systemd有时是一个 pita,我在 Go 中编写了一个包装脚本,这使得部署节点项目变得非常容易:

# Install
curl https://rootprojects.org/serviceman/dist/linux/amd64/serviceman -o serviceman
chmod +x ./serviceman
sudo serviceman /usr/local/bin
# Use
cd ./my/node/project
sudo serviceman --username $(whoami) --cap-net-bind add npm start

or, if your server isn't called 'server.js' (de facto standard), or extra options:或者,如果您的服务器没有被称为“server.js”(事实上的标准),或者额外的选项:

cd ./my/node/project
sudo serviceman --username $(whoami) --cap-net-bind add node ./my-server-thing.js -- --my-options

All that does is create your systemd file for you with sane defaults.所做的只是使用健全的默认值为您创建systemd文件。 I'd recommend you check out the systemd documentation as well, but it is a bit hard to grok and there are probably more confusing and otherwise bad tutorials than there are simple and otherwise good tutorials.我建议您也查看systemd文档,但它有点难以理解,并且可能比简单而好的教程更令人困惑和糟糕的教程。

Don't use AWS / EC2 unless you're an expert除非您是专家,否则不要使用 AWS / EC2

I responded to that question you mentioned: https://stackoverflow.com/a/58388665/151312我回答了你提到的那个问题: https://stackoverflow.com/a/58388665/151312

It'll probably get a bunch of downvotes from AWS die-hards... but:它可能会从 AWS 顽固分子那里得到一堆反对票……但是:

Don't use AWS.不要使用 AWS。 Use a VPS.使用 VPS。

I really like Digital Ocean and Vultr .我真的很喜欢Digital OceanVultr

Also, there are Greenlock DNS-01 plugins for both of those.此外,这两个都有 Greenlock DNS-01 插件。 That will make your life real easy.这将使您的生活变得真正轻松。

HTTP-01 vs DNS-01 validation HTTP-01 与 DNS-01 验证

The default validations for Greenlock MUST go over HTTP on port 80. That's part of the spec. Greenlock 的默认验证必须是 go 而不是端口 80 上的 HTTP。这是规范的一部分。 They CANNOT go over HTTPS, or over any other port.他们不能通过HTTPS或任何其他端口进行 go。

However, if you need SSL / TLS for private networking (which is probably not your issue), you can use DNS-01 plugins.但是,如果您需要 SSL / TLS 用于私有网络(这可能不是您的问题),您可以使用 DNS-01 插件。 As mentioned above, it's really simple to integrate with Digital Ocean, Vultr, and a number of others:如上所述,与 Digital Ocean、Vultr 和其他一些集成非常简单:

There are about a dozen different plugins.大约有十几个不同的插件。 You don't have to use them except for wildcard domains and private networking, but if you think managing the DNS and your VPS in the same place would be a benefit to you, I highly recommend using DNS-01 instead of HTTP-01.除了通配符域和专用网络之外,您不必使用它们,但是如果您认为在同一个地方管理 DNS 和您的 VPS 对您有好处,我强烈建议您使用 DNS-01 而不是 HTTP-01。

Port forwarding is a no go端口转发是没有 go

Don't port-forward unless you're an expert and you know what you're doing and why.除非您是专家并且知道自己在做什么以及为什么,否则不要进行端口转发。 You're gonna have a hard time and things aren't going to work as you expect.你会遇到困难,事情不会像你期望的那样工作。

How do you become an expert... lots of ways (and it's not hard )... but, as I understand it, it isn't really going to help you achieve your most immediate goal.您如何成为专家...有很多方法(这并不)...但是,据我了解,它并不能真正帮助您实现最直接的目标。

Sorry I can't be more helpful than that, but it's a big topic.对不起,我不能比这更有帮助,但这是一个很大的话题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM