nginx - 如何使 lightttp 和 nginx 运行在具有不同 IP 地址(相同接口(interface))的同一端口上?

标签 nginx port lighttpd

我在 RPi 上运行 PiHole,同时运行 Nginx 代理服务器。我必须让它们都监听端口 80,在这种情况下,pihole 必须让 lighttpd 监听端口 80。 为了解决这个问题,我在同一个接口(interface)中创建了两个ips地址(192.168.0.2和192.168.0.3),我想将它们都提供给lighttpd和Nginx。我能够更改lighttpd配置(仅在192.168.0.3上监听),并且我认为一切正常。然后我的 nginx 服务器失败了,我猜是因为通配符使 nginx 在每个 IP 地址中监听端口 80。

Nginx 当前状态

Jun 25 00:30:30 sousahost nginx[3040]: nginx: [warn] conflicting server name "" on 0.0.0.0:80, ignored
Jun 25 00:30:30 sousahost nginx[3040]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 25 00:30:31 sousahost nginx[3040]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 25 00:30:31 sousahost nginx[3040]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 25 00:30:32 sousahost nginx[3040]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jun 25 00:30:32 sousahost nginx[3040]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

在这种情况下我该如何解决我的问题?我想明显的解决方案是告诉 Nginx 仅监听某个 IP 地址,但我无法弄清楚(这可能吗?)。如何确保 Nginx 只列出某个 IP?

我的大部分配置都是这样的:

server {
    listen 192.168.1.3:80;
    return 301 https://$host$request_uri;
}

server {

    listen 443;
    server_name ads.sousa.host;
    ssl_certificate           /etc/nginx/ssl/pi.crt;
    ssl_certificate_key       /etc/nginx/ssl/pi.key;

    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    access_log            /var/log/nginx/pi.log;

    location / {

      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-Forwarded-Proto $scheme;

      # Fix the “It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://192.168.1.3:80;
      proxy_read_timeout  90;

      proxy_redirect      http://192.168.1.3:80 https://ads.sousa.host/admin;
    }
  }

另外,我思考得好吗?在同一接口(interface)上创建两个 ip 是一个有效且良好的解决方案吗?我愿意接受任何建议。

最佳答案

您应该尝试 listen 指令上的 bind 选项,这应该会阻止 nginx 尝试获取通配符地址。请参阅this document了解更多。

listen 192.168.0.2:80 bind;

这对于多个接口(interface)是有效的。但不确定一个接口(interface)上的多个地址是否有效。

关于nginx - 如何使 lightttp 和 nginx 运行在具有不同 IP 地址(相同接口(interface))的同一端口上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44742194/

相关文章:

rest - 如何为 RESTful API 配置 nginx?

Docker wordpress/nginx-proxy/nginx-proxy-companion - 让加密自动更新 - 更新图像并重新启动?

android - 使用 Lighttpd 在 Android 中进行视频流

在 Lighttpd 中保持连接模式 (HTTPS | HTTP) 的重定向规则

GitLab 后缀配置邮件未发送

javascript - CORS、通过 vagrant 的 nginx,以及通过 browsersync 提供服务的站点

java - 启动Tomcat未能初始化与ProtocolHandler关联的终点

node.js - Node : Set different domain name on different port

port - getsockname 返回无效地址

php - 升级的PHP。控制台显示 5.3 但 phpinfo 仍然显示 5.1.2