每当我向我的 Ubuntu 服务器发出请求时,我都会收到一个名为">404 - 未找到"的网页。因此,每当我在chrome中输入IP地址时,它都会给我404。
最初我认为这是一个nginx问题,因为我认为反向代理不起作用。我不认为它有效,因为当我进入我的域 wwww.mydomain.com 时,它会给我与我一直得到的相同的 404 页面。
我也可以拿 www.mydomain.com:4000,它会加载网站。目前我仍然可以这样做,我也可以去我的IP地址222.222.222.222:4000工作。任何命中 222.222.222.222 的内容都不起作用,并且将显示 404 页面(默认端口 80(。
我尝试查找许多不同的解决方案,但无法弄清楚如何解决它。我终于求助于我的 Ubuntu 服务器的核弹并重置了一切。当我这样做时,我仍然得到相同的 404 页面。 此外,404页面让我质疑,即使它是一个nginx问题,它也没有nginx。所有页面都说是 404 - 未找到
向我的 IP 地址发出请求时收到的 404 页面
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
</body>
</html>
我的nginx.conf文件,我注释掉了/etc/nginx/conf.d/*.conf来测试,看看我是否可以在这个文件中使用我的东西来解决问题。不过,在 chrome 中转到我的域时,我仍然会得到相同的 404 页面。我开始认为其他事情可能是问题的另一个原因。
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
#include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name mydomain.com www.mydomain.com;
location / {
proxy_pass http://127.0.0.1:4001;
}
}
}
我在 mydomain.conf 文件中为 nginx 提供的配置。
server {
listen 80;
server_name mydomain.com www.mydomain.com;
location / {
proxy_pass http://127.0.0.1:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
我已经关闭了nginx并转到chrome中的IP地址,但仍然得到相同的404页面。我觉得这意味着它一定是不是nginx的东西的问题。我唯一使用的其他东西是使用express的pm2和nodejs。可能是我的 Ubuntu 服务器有问题吗?我也为服务器进行了端口转发,但没有运气。
我运行了命令sudo nc -l 80并遇到了一些奇怪的东西。当我转到chrome(不是真实的(222.222.222.222中的IP地址时,我没有得到任何响应;但是,当我点击 192.168.1.175 时,我确实得到了来自命令的响应。
UFW目前
22/tcp ALLOW Anywhere
Nginx Full ALLOW Anywhere
OpenSSH ALLOW Anywhere
Apache Full ALLOW Anywhere
4001 ALLOW Anywhere
4000 ALLOW Anywhere
80 ALLOW Anywhere
402 DENY Anywhere
4002 ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
Nginx Full (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)
Apache Full (v6) ALLOW Anywhere (v6)
4001 (v6) ALLOW Anywhere (v6)
4000 (v6) ALLOW Anywhere (v6)
80 (v6) ALLOW Anywhere (v6)
402 (v6) DENY Anywhere (v6)
4002 (v6) ALLOW Anywhere (v6)
更新
当我作为 80 以外的任何其他端口进入域时,因此在我的情况下,https 的 443 它可以工作。由于某种原因,我认为每个端口都可以工作,但端口 80 除外。
也许它与 ubuntu 防火墙有关,您可以尝试使用命令行允许访问该端口
sudo ufw allow 4000/tcp
天哪!
看起来当我关闭服务器时,我仍然可以在端口 404 上获得 80。所以我当时就像这到底是什么打击。我决定重新启动我的路由器,就像魔术一样,一切都工作了。不知何故,222.222.222.222 击中了路由器而不是服务器。尽管端口 80 被转发到路由器上的服务器。不确定路由器如何决定不转发它并尝试自己处理它。