Nginx不能在域名上工作,但在IP地址上可以正常工作?

问题描述:

为什么我会得到这个页面的这个网站不能到达但是在我的终端上似乎没有错误?Nginx不能在域名上工作,但在IP地址上可以正常工作?

当我通过IP地址访问服务器它是好的:

enter image description here

但是随着域名,我得到这个:

enter image description here

$ sudo systemctl status nginx 
● nginx.service - A high performance web server and a reverse proxy server 
    Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) 
    Active: active (running) since Thu 2017-04-06 04:19:23 BST; 7h ago 
    Process: 7248 ExecStart=/usr/bin/nginx -g pid /run/nginx.pid; error_log stderr; (code=exited, status=0/SUCCESS) 
Main PID: 7250 (nginx) 
    Tasks: 2 (limit: 512) 
    CGroup: /system.slice/nginx.service 
      ├─7250 nginx: master process /usr/bin/nginx -g pid /run/nginx.pid; error_log stderr 
      └─7251 nginx: worker process         

Apr 06 04:19:23 localhost systemd[1]: Starting A high performance web server and a reverse proxy server... 
Apr 06 04:19:23 localhost systemd[1]: Started A high performance web server and a reverse proxy server. 
Apr 06 04:20:00 localhost nginx[7248]: 2017/04/06 04:20:00 [error] 7251#7251: *6 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 183.171 
Apr 06 07:14:44 localhost nginx[7248]: 2017/04/06 07:14:44 [error] 7251#7251: *506 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 195.2 
Apr 06 08:27:06 localhost nginx[7248]: 2017/04/06 08:27:06 [error] 7251#7251: *574 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 138.2 
Apr 06 11:04:58 localhost nginx[7248]: 2017/04/06 11:04:58 [error] 7251#7251: *835 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 183.1 
Apr 06 11:17:27 localhost nginx[7248]: 2017/04/06 11:17:27 [error] 7251#7251: *841 open() "/usr/share/nginx/html/robots.txt" failed (2: No such file or directory), client: 66.249 
Apr 06 11:31:40 localhost nginx[7248]: 2017/04/06 11:31:40 [error] 7251#7251: *845 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 183.1 
Apr 06 11:32:56 localhost 

这似乎是错误:

*6 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 183.171 

这是什么意思?它与域名无关!

这是我的配置的一部分:

server { 
    listen 80; 
    server_name example.co.uk www.example.co.uk; 

    location/{ 
     root /usr/share/nginx/html; 
     index index.html index.htm; 
    } 
} 

server { 
    listen 443 ssl; 
    server_name example.co.uk www.example.co.uk; 

    ssl_certificate /etc/letsencrypt/live/example.co.uk/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/example.co.uk/privkey.pem; 

    location/{ 
     root /usr/share/nginx/html; 
     index index.html index.htm; 
    } 

    location ~ /.well-known { 
      allow all; 
    } 
} 

server { 
    listen 8888 ssl; 
    server_name example.co.uk www.example.co.uk; 

    ssl_certificate /etc/letsencrypt/live/example.co.uk/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/example.co.uk/privkey.pem; 

    location ~ /.well-known { 
     allow all; 
    } 

    location/{ 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header Host  $http_host; 
      proxy_pass   http://127.0.0.1:3838; 
    } 

} 

测试代码:

$ sudo nginx -t 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
nginx: configuration file /etc/nginx/nginx.conf test is successful 

这是所有工作的罚款之前,但现在突然停了下来。

任何想法?

我按照这个guide在我的Arch Linux上安装Nginx btw。

的步骤我走:

$ sudo pacman -Syu 
$ sudo pacman -S nginx 

开始Nginx的服务,并使其在开机使用命令来启动:

$ sudo systemctl start nginx 
$ sudo systemctl enable nginx 

编辑:

我现在已经卸载Ngnix和重新安装它,但它不再工作,即使重新启动,但没有任何配置到/etc/nginx/nginx.conf。我得到的是此网站无法访问'浏览器

为什么!??

netstat检查,我可以看到80端口是在列表中:

$ sudo netstat -tulpn 

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:27017   0.0.0.0:*    LISTEN  5361/mongod   
tcp  0  0 0.0.0.0:5355   0.0.0.0:*    LISTEN  3666/systemd-resolv 
tcp  0  0 0.0.0.0:80    0.0.0.0:*    LISTEN  10701/nginx: master 
tcp  0  0 0.0.0.0:22    0.0.0.0:*    LISTEN  3667/sshd   
tcp  0  0 0.0.0.0:3838   0.0.0.0:*    LISTEN  32434/shiny-server 
tcp6  0  0 :::5355     :::*     LISTEN  3666/systemd-resolv 
tcp6  0  0 :::3030     :::*     LISTEN  17325/node /usr/loc 
tcp6  0  0 :::22     :::*     LISTEN  3667/sshd   
tcp6  0  0 :::3000     :::*     LISTEN  17325/node /usr/loc 
udp  0  0 0.0.0.0:5355   0.0.0.0:*       3666/systemd-resolv 
udp6  0  0 :::5355     :::*        3666/systemd-resolv 

编辑2:

我创建了一个访问日志。但我没有看到任何重大的错误有:

$ more -f /etc/nginx/logs/access.log 
183.171.92.177 - - [06/Apr/2017:12:38:09 +0100] "GET/HTTP/1.1" 200 612 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/57.0.2987.98 Chrome/57.0.2987.98 Safari/537.36" "-" 
183.171.92.177 - - [06/Apr/2017:12:38:09 +0100] "GET /favicon.ico HTTP/1.1" 404 571 "http://xxx.xxx.xxx.xx/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/57.0.2987.98 Chrome/57.0.2987.98 Safari/537.36" "-" 

查找内容从Nginx的访问日志怎么回事!在检查之前,确保您的记录足够。您可以使用以下log_format。

log_format main '$host - $remote_addr - $remote_user - [$time_local] - $document_root - $document_uri - $request - $status - $body_bytes_sent - $http_referer'; 

重新启动您的Nginx服务并发出一些请求。您需要确定请求是否到达服务器。访问日志应该能够清楚地表明发生了什么。

+0

只有使用域​​名,但在IP地址上正常时才会发生。看到我上面编辑的版本。谢谢。 – laukok