2017-04-06 44 views
0

爲什麼我會得到這個頁面的這個網站不能到達但是在我的終端上似乎沒有錯誤?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" "-" 

回答

0

查找內容從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

相關問題