使用Nginx反向代理的子域上的ZNC?

时间:2015-12-12 06:15:20

标签: nginx reverse-proxy

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

我关注了instructions on the official 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/;
    }
}

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

1 个答案:

答案 0 :(得分:3)

我自己一直在与这个问题作斗争,而且非常令人沮丧!但我找到了一个解决方案,它现在为我工作,让我知道你的想法......

HIGH LEVEL

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

<强>详情

1. split the listener sections between AllowWeb and AllowIRC

这对我来说是最大的举动,在梳理了一些博客文章+ 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>
...

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

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)

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

5. configure nginx to forward ssl to your localhost web interface

这是你上面的例子非常重要的地方。我已将我的帖子作为参考,但它们几乎相同。

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;
    }
}

好运!