0

我正在尝试为我的 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 Vagrantfile--port中的访客端口和 `--dispatcher-port` 的主机端口

但它说

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

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

4

1 回答 1

2

您已经在端口 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)

于 2017-03-23T07:16:22.517 回答