http – Nginx正在侦听端口80或443但没有响应

我的服务器工作得很好,直到几个小时前,当它以某种方式停止接听电话时,

我认为独角兽工作正常(卷曲localhost:3000作品 – 其中3000是独角兽的港口)

我跑了:

sudo netstat -anltp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      5664/mysqld     
tcp        0      0 my.public.ip.address:80        0.0.0.0:*               LISTEN      6825/nginx      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2737/sshd       
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      6389/unicorn.rb -E 
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      2934/master     
tcp        0      0 my.public.ip.address:443       0.0.0.0:*               LISTEN      6825/nginx      
tcp        0      0 my.public.ip.address:22        a.different.ip.number:49372      ESTABLISHED 3433/sshd: user
tcp        0    232 my.public.ip.address:22        a.different.ip.number:49909      ESTABLISHED 6887/sshd: user
tcp6       0      0 :::22                   :::*                    LISTEN      2737/sshd       
tcp6       0      0 :::25                   :::*                    LISTEN      2934/master     

看来端口80和端口443都是由nginx打开的,但是当我尝试卷曲localhost时:

$curl localhost
curl: (7) Failed connect to localhost:80; Connection refused
$curl https://localhost
curl: (7) Failed connect to localhost:443; Connection refused

ssh使用的端口22似乎工作正常.因为我通过ssh登录了盒子:

这是我的/etc/nginx/nginx.conf文件:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/app/nginx_access.log;
    error_log  /var/log/app/nginx_error.log;

    gzip on;
    gzip_disable "msie6";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

这是我的/ etc / nginx / sites-enabled / app文件:

upstream unicorn {
  server 0.0.0.0:3000 fail_timeout=0;
}

server {
  listen my.ip.num.ber:80;
  server_name www.mydomainname.com;

  location / {
    rewrite ^ https://$server_name$request_uri permanent;
  }
}

server {
  listen my.ip.num.ber:443 ssl;
  server_name www.mydomainname.com;

  client_max_body_size 4G;
  keepalive_timeout 5;

  root /var/www/mydomainname/releases/20140417140248/public/;

  try_files $uri $uri/index.html $uri.html @unicorn;

  ssl_certificate      /srv/ssl/mydomainname.chained.crt;
  ssl_certificate_key  /srv/ssl/mydomainname.key;

  ssl_session_timeout  5m;

  ssl_protocols  SSLv2 SSLv3 TLSv1;
  ssl_ciphers  HIGH:!aNULL:!MD5;
  ssl_prefer_server_ciphers   on;


  location /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    # alias /var/www/mydomainname/releases/20140417140248/public/;
  }


  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_intercept_errors on;

    proxy_pass http://unicorn;
  }

}

从使用nmap的扫描中我看到:

$sudo nmap -sS -O 127.0.0.1

Starting Nmap 6.40 ( http://nmap.org ) at 2014-04-17 14:44 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000062s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
25/tcp   open  smtp
3000/tcp open  ppp
3306/tcp open  mysql
No exact OS matches for host (If you know what OS is running on it, see http://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=6.40%E=4%D=4/17%OT=22%CT=1%CU=30717%PV=N%DS=0%DC=L%G=Y%TM=534FE8C
OS:8%P=x86_64-unknown-linux-gnu)SEQ(SP=107%GCD=1%ISR=10B%TI=Z%CI=I%II=I%TS=
OS:8)OPS(O1=MFFD7ST11NW7%O2=MFFD7ST11NW7%O3=MFFD7NNT11NW7%O4=MFFD7ST11NW7%O
OS:5=MFFD7ST11NW7%O6=MFFD7ST11)WIN(W1=AAAA%W2=AAAA%W3=AAAA%W4=AAAA%W5=AAAA%
OS:W6=AAAA)ECN(R=Y%DF=Y%T=40%W=AAAA%O=MFFD7NNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%
OS:S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%
OS:RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W
OS:=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)
OS:U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%D
OS:FI=N%T=40%CD=S)

Network Distance: 0 hops

OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 12.27 seconds

任何线索?

谢谢

加成:

在使用listen 80和listen 443配置的nginx重新启动后,这是我的新netstat:

sudo netstat -ntulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      5664/mysqld     
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7845/nginx      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2737/sshd       
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      6389/unicorn.rb -E 
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      2934/master     
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      7845/nginx      
tcp6       0      0 :::22                   :::*                    LISTEN      2737/sshd       
tcp6       0      0 :::25                   :::*                    LISTEN      2934/master     
udp        0      0 0.0.0.0:57284           0.0.0.0:*                           2418/dhclient   
udp        0      0 0.0.0.0:68              0.0.0.0:*                           2418/dhclient   
udp        0      0 my.public.ip.addr:123       0.0.0.0:*                           3550/ntpd       
udp        0      0 127.0.0.1:123           0.0.0.0:*                           3550/ntpd       
udp        0      0 0.0.0.0:123             0.0.0.0:*                           3550/ntpd       
udp6       0      0 :::55187                :::*                                2418/dhclient   
udp6       0      0 ::1:123                 :::*                                3550/ntpd       
udp6       0      0 :::123                  :::*                                3550/ntpd  

最佳答案 你的nginx听my.ip.num.ber,但你尝试连接到localhost,几乎总是127.0.0.1.你的nginx不听这个ip.

只需从listen指令中删除my.ip.num.ber即可.让他们听80;并听443 ssl;.

点赞