为什么我的此网站无法访问这个页面,但我的终端上似乎没有错误?
当我通过 IP地址访问服务器时,没关系:
但是使用域名,我明白了:
$ 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 :(得分: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服务并提出一些请求。您需要确定请求是否甚至到达服务器。访问日志应该能够清楚地显示正在进行的操作。
答案 1 :(得分:0)
由于您没有dns服务器,因此要向具有指定域名的服务器发送请求,您需要在/ etc / hosts中添加一个条目(此路径取决于您的本地计算机系统)客户端计算机的文件。 您需要在该文件中添加以下行,就像这样:
sudo nano /private/etc/hosts
...并且:
# The client /etc/hosts file
<ip-of-your-server> www.yourdomainname.com