Ubuntu

nginx 無法綁定到埠 80.. 埠 80 上沒有執行

  • August 16, 2020

我正在嘗試在 Ubuntu 11.04 上設置 nginx。我大致遵循了此處的說明:http: //library.linode.com/frameworks/sinatra/debian-6-squeeze。我知道它適用於 Debian,但我基本上採取了這些步驟,然後在 google 上搜尋“如何在 ubuntu 11.04 中執行 x”雖然,我確實從他們的庫中提取了 init 腳本。

Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

命令:‘sudo lsof -i:80’ 不會返回在埠 80 上執行的任何內容。

我該如何解決這個問題或任何關於可能出錯的想法?

我在全新的 Ubuntu 安裝上看到Nginx + uWSGI - 綁定錯誤埠 80並嘗試重新啟動電腦並執行一次,我得到了同樣的錯誤。執行一次後,我執行 lsof 命令。

更新

sudo netstat -ltnp 返回:

 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:22              0.0.0.0:*               LISTEN      1998/sshd  

 tcp6       0      0 :::22                 :::*                    LISTEN      1998/sshd

nestat -a 返回:

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 *:ssh                   *:*                     LISTEN     
tcp        0    176 matterhorn.noahc.ne:ssh 173-26-190-206.cl:26467 ESTABLISHED
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      
udp        0      0 matterhorn.noahc.:35332 10504.x.rootbsd.net:ntp ESTABLISHED
udp        0      0 matterhorn.noahc.:53298 tick.tadatv.com:ntp     ESTABLISHED
udp        0      0 matterhorn.noahc.:54371 ns1.baribault.net:ntp   ESTABLISHED
udp        0      0 matterhorn.noahc.:38304 tardis.chpc.utah.ed:ntp ESTABLISHED
Active UNIX domain sockets (servers and established)

Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     684      @/com/ubuntu/upstart
unix  2      [ ]         DGRAM                    730      @/org/kernel/udev/udevd
unix  6      [ ]         DGRAM                    4316     /dev/log
unix  2      [ ]         DGRAM                    11447    
unix  3      [ ]         STREAM     CONNECTED     10466    
unix  3      [ ]         STREAM     CONNECTED     10465    
unix  2      [ ]         DGRAM                    11411    
unix  3      [ ]         STREAM     CONNECTED     2958     
unix  3      [ ]         STREAM     CONNECTED     2957     
unix  2      [ ]         DGRAM                    4518     
unix  2      [ ]         DGRAM                    2902     
unix  2      [ ]         DGRAM                    2614     
unix  3      [ ]         STREAM     CONNECTED     1284     @/com/ubuntu/upstart
unix  3      [ ]         STREAM     CONNECTED     4131     
unix  3      [ ]         DGRAM                    733      
unix  3      [ ]         DGRAM                    732      
unix  3      [ ]         STREAM     CONNECTED     1038     @/com/ubuntu/upstart
unix  3      [ ]         STREAM     CONNECTED     2088    

一種可能性是,由於某種原因,nginx 兩次綁定到埠 80。

如果它試圖這樣做,它將失敗。一個範例可能是綁定到 IPV6 和 IPV4,或者將其綁定到公共 ip 和萬用字元 ip。

檢查您的 nginx 配置以確保它只綁定一次。

嘗試:

http{

   server {

       listen 80;
       listen localhost;  # <- probably will fix your problem

       location / {
       root /data/www;
       }

       location /images/ {
       root /data;
       }
   }
}

引用自:https://serverfault.com/questions/308176