带有 Nginx 反向代理的子域上的 ZNC?

wil*_*ill 4 reverse-proxy nginx

我目前通过http://www.example.net:6667在我的 VPS 上访问 ZNC ,但我正在尝试配置 Nginx,因此它只能通过http://znc.example.net访问。

我按照官方 ZNC wiki 上说明进行操作,但是尽管尝试了很多小时的不同方法,我还是继续收到 Firefox 的“找不到服务器”错误。

里面的一个server/etc/nginx/sites-available/example.net如下:

server {
    listen 80;
    server_name znc.example.net;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:6667/;
    }
}
Run Code Online (Sandbox Code Playgroud)

TrustedProxy = 127.0.0.1我的~/.znc/configs/znc.conf文件中也有,那么我哪里出错了?谢谢。

seb*_*o91 9

我自己一直在与这个问题作斗争,这太令人沮丧了!但我想出了一个解决方案,现在对我有用,让我知道你的想法......

高水平

1. split the listener sections between AllowWeb and AllowIRC
2. disable SSL termination on web listener, enable SSL on irc listener
3. configure web listener for localhost
4. remove 'Host =' for IRC listener (bind to all interfaces)
5. configure nginx to forward ssl to your localhost web interface
Run Code Online (Sandbox Code Playgroud)

细节

1. split the listener sections between AllowWeb and AllowIRC
Run Code Online (Sandbox Code Playgroud)

这对我来说是最大的举措,在梳理了许多博客文章 + znc 配置文档后,我注意到所有 nginx 配置设置都只涉及 Web 界面。出于不同的目的将它们拆分为两个侦听器将 nginx 处理的部分解耦,同时让另一个条目由 znc ssl 保护。我已经添加了znc.conf下面的代码片段:

// WARNING
//
// Do NOT edit this file while ZNC is running!
// Use webadmin or *controlpanel instead.
//
// Altering this file by hand will forfeit all support.
//
// But if you feel risky, you might want to read help on /znc saveconfig and /znc rehash.
// Also check http://en.znc.in/wiki/Configuration

AnonIPLimit = 10
ConnectDelay = 5
HideVersion = false
LoadModule = webadmin
MaxBufferSize = 500
PidFile = /var/run/znc/znc.pid
ProtectWebSessions = true
SSLCertFile = /var/lib/znc/znc.pem
SSLCiphers = EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
SSLProtocols = -SSLv2 -SSLv3 -TLSv1 +TLSv1.1 +TLSv1.2
ServerThrottle = 30
Skin = dark-clouds
StatusPrefix = *
Version = 1.6.5

<Listener listener0>
    AllowIRC = false
    AllowWeb = true
    Host = localhost
    IPv4 = true
    IPv6 = false
    Port = 8080
    SSL = false
    URIPrefix = /
</Listener>

<Listener listener1>
    AllowIRC = true
    AllowWeb = false
    IPv4 = true
    IPv6 = false
    Port = 9191
    SSL = true
    URIPrefix = /
</Listener>
...
Run Code Online (Sandbox Code Playgroud)

其余的几乎是定义用户和添加频道时的标准选项。

2. disable SSL termination on web listener, enable SSL on irc listener
3. configure web listener for localhost
4. remove 'Host =' for IRC listener (bind to all interfaces)
Run Code Online (Sandbox Code Playgroud)

鉴于它不受 ssl 的保护,强制 Web 界面只能路由到 localhost。nginx 代理将代表您终止 ssl 会话(我使用的是 letencrypt)并将连接路由proxy_pass到您的 localhost 侦听器。irc 连接将直接绑定到您的 irc 侦听器,其中 ssl 已打开并利用znc.pem您之前定义的。这些说明对定义很有用znc.pem,在这种情况下,我也添加了我的说明dhparam.pem(必不可少!)。

5. configure nginx to forward ssl to your localhost web interface
Run Code Online (Sandbox Code Playgroud)

这就是您上面的示例非常切中要害的地方。我已经发布了我的作为参考,但它们几乎相同。

server {
    listen      443 ssl http2;
    server_name irc.example.com;
    access_log  /var/log/nginx/irc.log combined;

    ssl_certificate     /etc/letsencrypt/live/irc.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/irc.example.com/privkey.pem;
    ssl_dhparam         /etc/letsencrypt/live/irc.example.com/dhparam.pem;

    location /.well-known {
        alias /var/www/irc/.well-known;
    }

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header      Host             $host;
        proxy_set_header      X-Real-IP        $remote_addr;
        proxy_set_header      X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header      X-Client-Verify  SUCCESS;
        proxy_set_header      X-Client-DN      $ssl_client_s_dn;
        proxy_set_header      X-SSL-Subject    $ssl_client_s_dn;
        proxy_set_header      X-SSL-Issuer     $ssl_client_i_dn;
        proxy_read_timeout    1800;
        proxy_connect_timeout 1800;
    }
}
Run Code Online (Sandbox Code Playgroud)

祝你好运!