如何在Vagrant和ruby-debug-ide上配置端口 [英] How to configure ports on Vagrant and ruby-debug-ide
问题描述
我正在尝试为我的Web应用程序配置调试器,但是在为其指定正确的端口时遇到了麻烦.
Vagrantfile:
I’m trying to configure debugger for my web application, but I run into trouble with specifying correct ports for it.
Vagrantfile:
config.vm.network :private_network, ip: "192.168.68.8"
config.vm.network :forwarded_port, guest: 80, host: 8080
/etc/hosts(在我的主机上)
/etc/hosts (on my host machine)
192.168.68.8 mysite.com
我安装了这两个gem进行调试
I installed these two gems for debugging
gem 'ruby-debug-ide', group: [:development,:test]
gem 'debase', group: [:development,:test]
我读到为了在流浪汉上使用ruby-debug-ide,我应该运行
rdebug-ide --host 0.0.0.0 --port 80 --dispatcher-port 8080 -- bin/rails s
其中--port
应该是Vagrantfile的来宾端口和`--dispatcher-port``
I read that in order to use ruby-debug-ide on vagrant, I should run
rdebug-ide --host 0.0.0.0 --port 80 --dispatcher-port 8080 -- bin/rails s
where --port
should be guest port from Vagrantfile and host port for `--dispatcher-port``
但是它说
Permission denied - bind(2) for "0.0.0.0" port 80
另一方面,如果尝试更改Vagrantfile中的端口,我将失去从127.0.0.1:specified_port访问我的应用程序的机会,但仍然可以从mysite.com进行操作,这令人困惑
On the other side, if I try to change those ports in Vagrantfile, I lose the opportunity to reach my application from 127.0.0.1:specified_port, but still can do it from mysite.com, which is confusing
推荐答案
您已经在80端口(apache或nginx)上监听了某些内容,因此无法在此端口上进行绑定.您可以执行以下任一操作
you already have something listening on port 80 (apache or nginx) so you cant bind on this port. You can do one of the following
- 在另一个端口(例如3000)上启动导轨
在流浪汉中开始rdebug-ide --host 0.0.0.0 --port 3000 --dispatcher-port 3000 -- bin/rails s
如果您在vagrant文件中使用专用网络IP,则无需转发端口,因为您将使用其自己的IP访问VM服务器
If you use a private network IP in your vagrantfile you dont need to forward port as you'll access your VM server using its own IP
- 检查在端口80上侦听的内容
在您的VM中运行sudo netstat -nltp
,检查绑定端口80的进程并杀死它
run sudo netstat -nltp
in your VM, check the process which binds the port 80 and kill it
例如
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)
so you'll kill the apache2 process (PID 1827)
这篇关于如何在Vagrant和ruby-debug-ide上配置端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!