在数字海洋错误上使用端口80和节点:收听EADDRINUSE

时间:2014-06-25 23:44:21

标签: node.js port digital-ocean

我正在尝试在Digital Ocean服务器上运行最简单的节点服务器。我使用port 8080开发并测试了代码没有问题。但是,现在我想使用port 80,以便在导航到我的服务器的IP地址时不需要指定端口(因此它将默认)。

当我将端口更改为80并以sudo运行应用程序时,即使我没有在服务器上运行任何其他应用程序(根本),我也会获得Error: listen EADDRINUSE。有没有办法清除port 80使用?

我在这里查看了How to fix Error: listen EADDRINUSE while using nodejs? 但这些建议都没有奏效。这绝对是我服务器上唯一的程序。

我的代码中没有其他进程正在侦听任何端口。实际上我的服务器上根本没有运行app,所以我不明白端口是如何使用的。谢谢你的帮助

编辑。以下是运行netstat的内容:

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 192.241.228.76:ssh      mobile-166-137-17:62351 ESTABLISHED
tcp        0      0 192.241.228.76:ssh      199-241-200-214.P:41732 ESTABLISHED
tcp        0      0 192.241.228.76:9090     199-241-200-214.P:38480 ESTABLISHED
tcp        0      0 192.241.228.76:ssh      mobile-166-137-17:45329 ESTABLISHED
tcp        0      0 192.241.228.76:ssh      199-241-200-214.P:47247 ESTABLISHED
tcp        0    308 192.241.228.76:ssh      199-241-200-214.P:44441 ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  8      [ ]         DGRAM                    7710     /dev/log
unix  3      [ ]         STREAM     CONNECTED     1113212  
unix  3      [ ]         STREAM     CONNECTED     7405     @/com/ubuntu/upstart
unix  3      [ ]         STREAM     CONNECTED     7394     
unix  3      [ ]         STREAM     CONNECTED     1113211  
unix  2      [ ]         DGRAM                    9255     
unix  3      [ ]         STREAM     CONNECTED     7681     
unix  3      [ ]         STREAM     CONNECTED     7617     /var/run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     1113404  
unix  3      [ ]         STREAM     CONNECTED     1113682  
unix  2      [ ]         DGRAM                    1113070  
unix  2      [ ]         DGRAM                    1113287  
unix  3      [ ]         STREAM     CONNECTED     1113683  /var/run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     1113675  
unix  3      [ ]         STREAM     CONNECTED     7601     
unix  3      [ ]         STREAM     CONNECTED     7602     
unix  3      [ ]         STREAM     CONNECTED     7631     @/com/ubuntu/upstart
unix  3      [ ]         STREAM     CONNECTED     1114471  
unix  2      [ ]         DGRAM                    1111881  
unix  3      [ ]         STREAM     CONNECTED     1113411  
unix  3      [ ]         STREAM     CONNECTED     1113219  /var/run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     1113218  
unix  3      [ ]         STREAM     CONNECTED     1112008  
unix  3      [ ]         STREAM     CONNECTED     8858     @/com/ubuntu/upstart
unix  3      [ ]         DGRAM                    7439     
unix  3      [ ]         STREAM     CONNECTED     7682     /var/run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     8836     
unix  3      [ ]         STREAM     CONNECTED     1114472  
unix  3      [ ]         DGRAM                    7438     
unix  3      [ ]         STREAM     CONNECTED     1113412  /var/run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     1113676  
unix  2      [ ]         DGRAM                    1113552  
unix  3      [ ]         STREAM     CONNECTED     1113405  
unix  3      [ ]         STREAM     CONNECTED     7616     
unix  3      [ ]         STREAM     CONNECTED     7594     
unix  3      [ ]         STREAM     CONNECTED     1112002  
unix  2      [ ]         DGRAM                    1114349  
unix  3      [ ]         STREAM     CONNECTED     1112001  
unix  3      [ ]         STREAM     CONNECTED     1112009  /var/run/dbus/system_bus_socket

以下是运行ps -ax返回

的内容
 PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:05 /sbin/init
    2 ?        S      0:00 [kthreadd]
    3 ?        S      0:01 [ksoftirqd/0]
    5 ?        S<     0:00 [kworker/0:0H]
    7 ?        S      0:09 [rcu_sched]
    8 ?        S      0:00 [rcu_bh]
    9 ?        S      0:00 [migration/0]
   10 ?        S      0:14 [watchdog/0]
   11 ?        S<     0:00 [khelper]
   12 ?        S      0:00 [kdevtmpfs]
   13 ?        S<     0:00 [netns]
   14 ?        S<     0:00 [writeback]
   15 ?        S<     0:00 [kintegrityd]
   16 ?        S<     0:00 [bioset]
   17 ?        S<     0:00 [kworker/u3:0]
   18 ?        S<     0:00 [kblockd]
   19 ?        S<     0:00 [ata_sff]
   20 ?        S      0:00 [khubd]
   21 ?        S<     0:00 [md]
   22 ?        S<     0:00 [devfreq_wq]
   23 ?        S      2:16 [kworker/0:1]
   24 ?        S      0:00 [khungtaskd]
   25 ?        S      0:00 [kswapd0]
   26 ?        SN     0:00 [ksmd]
   27 ?        S      0:00 [fsnotify_mark]
   28 ?        S      0:00 [ecryptfs-kthrea]
   29 ?        S<     0:00 [crypto]
   41 ?        S<     0:00 [kthrotld]
   44 ?        S      0:00 [scsi_eh_0]
   45 ?        S      0:00 [scsi_eh_1]
   65 ?        S<     0:00 [deferwq]
   66 ?        S<     0:00 [charger_manager]
  119 ?        S      0:04 [jbd2/vda-8]
  120 ?        S<     0:00 [ext4-rsv-conver]
  254 ?        S      0:00 upstart-udev-bridge --daemon
  259 ?        Ss     0:00 /lib/systemd/systemd-udevd --daemon
  321 ?        Ss     0:00 dbus-daemon --system --fork
  351 ?        Ss     0:00 /lib/systemd/systemd-logind
  354 ?        Ssl    0:19 rsyslogd
  363 ?        S      0:00 upstart-file-bridge --daemon
  367 ?        S<     0:00 [kpsmoused]
  371 ?        S      0:00 [kworker/0:2]
  463 ?        S<     0:00 [kvm-irqfd-clean]
  730 ?        S      0:00 upstart-socket-bridge --daemon
  773 tty4     Ss+    0:00 /sbin/getty -8 38400 tty4
  777 tty5     Ss+    0:00 /sbin/getty -8 38400 tty5
  783 tty2     Ss+    0:00 /sbin/getty -8 38400 tty2
  784 tty3     Ss+    0:00 /sbin/getty -8 38400 tty3
  786 tty6     Ss+    0:00 /sbin/getty -8 38400 tty6
  811 ?        Ss     0:12 /usr/sbin/sshd -D
  817 ?        Ss     0:00 acpid -c /etc/acpi/events -s /var/run/acpid.socket
  819 ?        Ss     0:02 cron
  821 ?        Ss     0:00 atd
  898 tty1     Ss+    0:00 /sbin/getty -8 38400 tty1
  933 ?        S<     0:00 [kworker/u3:1]
  938 ?        S      0:00 [kauditd]
24995 ?        S      0:00 [kworker/u2:1]
29226 ?        S      0:07 [kworker/u2:0]
29542 ?        Ss     0:00 SCREEN
29543 pts/2    Ss+    0:00 /bin/bash
30826 pts/6    Ss+    0:00 -bash
30892 ?        Sl     0:00 nodejs index.js
30962 pts/1    R+     0:00 ps -ax

1 个答案:

答案 0 :(得分:0)

我收到了这个错误。即使地址未被使用,如果由于任何原因无法将进程附加到端口,Node似乎也会抛出此错误。

在我的情况下(数字海洋液滴)连接到端口80需要var SessionSchema = new Schema({ session: String, expires: String }, {collection: 'sessions'} );