【问题标题】:How to configure ports on Vagrant and ruby-debug-ide如何在 Vagrant 和 ruby​​-debug-ide 上配置端口
【发布时间】:2017-03-23 03:51:33
【问题描述】:

我正在尝试为我的 Web 应用程序配置调试器,但在为其指定正确端口时遇到了麻烦。 流浪文件:

config.vm.network :private_network, ip: "192.168.68.8"
config.vm.network :forwarded_port, guest: 80, host: 8080

/etc/hosts(在我的主机上)

192.168.68.8    mysite.com

我安装了这两个 gem 用于调试

gem 'ruby-debug-ide', group: [:development,:test]
gem 'debase', group: [:development,:test]

我读到为了在 vagrant 上使用 ruby​​-debug-ide,我应该运行 rdebug-ide --host 0.0.0.0 --port 80 --dispatcher-port 8080 -- bin/rails s 其中--port 应该是来自 Vagrantfile 的访客端口和 `--dispatcher-port 的主机端口

但它说

Permission denied - bind(2) for "0.0.0.0" port 80

另一方面,如果我尝试更改 Vagrantfile 中的这些端口,我将失去从 127.0.0.1:specified_port 访问我的应用程序的机会,但仍然可以从 mysite.com 访问,这令人困惑

【问题讨论】:

    标签: ruby vagrant ruby-debug-ide


    【解决方案1】:

    您已经在端口 80(apache 或 nginx)上监听了一些东西,因此您无法在此端口上绑定。您可以执行以下操作之一

    1. 在另一个端口(如 3000)上启动 rails

    在你的流浪开始rdebug-ide --host 0.0.0.0 --port 3000 --dispatcher-port 3000 -- bin/rails s

    如果您在 vagrantfile 中使用私有网络 IP,则不需要转发端口,因为您将使用自己的 IP 访问您的 VM 服务器

    1. 检查端口 80 上监听的内容

    在你的虚拟机中运行sudo netstat -nltp,检查绑定80端口的进程并杀死它

    例如

    vagrant@precise32:/etc/init.d$ sudo netstat -nltp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      512/rpcbind
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1827/apache2
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      652/sshd
    tcp        0      0 0.0.0.0:58397           0.0.0.0:*               LISTEN      539/rpc.statd
    tcp6       0      0 :::111                  :::*                    LISTEN      512/rpcbind
    tcp6       0      0 :::22                   :::*                    LISTEN      652/sshd
    ...
    

    所以你会杀死 apache2 进程(PID 1827)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-24
      • 1970-01-01
      • 1970-01-01
      • 2022-12-11
      相关资源
      最近更新 更多