即使Nginx在Ubuntu上运行也无法访问默认页面

时间:2019-05-31 03:56:36

标签: node.js angular nginx

我正在服务器上运行ubuntu 17.10,已经安装并正在运行nginx

sudo systemctl restart nginx 

sudo /etc/init.d/nginx status

可以执行并返回运行状态

    ● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-05-31 10:54:07 +08; 47min ago
     Docs: man:nginx(8)
  Process: 99211 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 99225 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 99213 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 99228 (nginx)
    Tasks: 3 (limit: 19660)
   Memory: 2.3M
      CPU: 10ms
   CGroup: /system.slice/nginx.service
           ├─99228 nginx: master process /usr/sbin/nginx -g daemon on; master…n;
           ├─99229 nginx: worker process
           └─99230 nginx: worker process

May 31 10:54:07 UbuntuSvr systemd[1]: Starting A high performance web serve…r...
May 31 10:54:07 UbuntuSvr systemd[1]: Started A high performance web server…ver.
Hint: Some lines were ellipsized, use -l to show in full.

但是,当我访问我的IP:8080(因为我将8080放在nginx配置上)或我的IP:80(我刚刚尝试)或我的IP:8082(因为我在{{3上构建了我的有角度的前端和配置apiBaseUrl时) }})显示

This site can’t be reached
ERR_CONNECTION_RESET

在Chrome和 safari can't open the page, ...because server where this page is located isn't responding在Safari上。

我试图检查防火墙:

sudo ufw status

它显示:

Status: active

To                         Action      From
--                         ------      ----
8082/tcp                   ALLOW       Anywhere                  
8080/tcp                   ALLOW       Anywhere                  
8082/tcp (v6)              ALLOW       Anywhere (v6)             
8080/tcp (v6)              ALLOW       Anywhere (v6)  

和其他检查:

netstat -natup | grep LISTEN

显示:

tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:3002            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:5355            0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::8080                 :::*                    LISTEN      -                   
tcp6       0      0 :::80                   :::*                    LISTEN      -                   
tcp6       0      0 :::86                   :::*                    LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      -                   
tcp6       0      0 :::5355                 :::*                    LISTEN      -   

sudo netstat -tanpl|grep nginx显示:

tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      99228/nginx: master 
tcp6       0      0 :::8080                 :::*                    LISTEN      99228/nginx: master 

这是我的/etc/nginx/sites-available/default文件内容:

> server {
>     listen 80 default_server;
>     listen [::]:80 default_server;
>  
>     root /var/www/html;
>     index index.html index.htm index.nginx-debian.html;
>  
>     server_name _;
>  
>     location / {
>         try_files $uri $uri/ /index.html =404;
>     } }

我已经通过ng build --prod构建了前端站点,并将生成的文件夹(位于“ dist”文件夹下)下的所有内容复制到/var/www/html/文件夹(其中也包含“ index.nginx-debian.html” “文件)

其他信息:我的后端在nodejs pm2上运行。在mongodb上运行的数据库。 更新:根据需要我的nginx.conf文件:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

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


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

我观察到的另一件事:如果我从服务器curl -I http://localhost:8080运行此命令,则会得到:

HTTP/1.1 200 OK
Server: nginx/1.14.0
Date: Fri, 31 May 2019 06:58:26 GMT
Content-Type: text/html
Content-Length: 700
Last-Modified: Fri, 31 May 2019 02:44:47 GMT
Connection: keep-alive
ETag: "5cf0951f-2bc"
Accept-Ranges: bytes

但是如果我用myserver IP替换localhost:

curl -I http://my.server.ip.address:8080

然后我得到了

curl: (7) Failed to connect to 13.67.51.66 port 8080: Connection timed out

我的服务器也使用Azure云服务,这会阻止ICMP,然后我不能使用IP从外部连接到我的服务器吗?那我该怎么办呢?

我期望从本地笔记本电脑尝试这些尝试之一,至少我可以获得: http://localhost:8082

但不是。

请问您知道有什么原因吗?我该怎么做呢? 非常感谢你!

0 个答案:

没有答案