每当从外部端口访问 Ubuntu 时,我该如何解决这个 404 问题。可能是 Ubuntu、pm2、nginx 或 express 问题
How can I fix this 404 issue that I am having whenever Ubuntu is accessed from an external port. It could be an Ubuntu, pm2, nginx, or express problem
每当我向 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 - Not Found
向我的 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;
}
}
}
我在 nginxmydomain.conf 文件中的配置
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 的东西的问题。我唯一使用的其他东西是 pm2 和使用 express 的 nodejs。会不会是我的 Ubuntu 服务器有问题?我也为服务器做了端口转发,但没有成功。
我有 运行 命令 sudo nc -l 80 和 运行 跨越一些奇怪的东西。当我转到 chrome 中的 IP 地址(不是真实地址)222.222.222.222 时,我没有得到任何响应;但是,当我点击 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 以外的任何其他端口访问域时,因此在我的情况下 443 用于 https 它有效。我假设每个端口都可以工作,但出于某种原因端口 80。
可能与ubuntu防火墙有关,您可以尝试使用命令行允许访问该端口
sudo ufw allow 4000/tcp
我的天哪!
看起来当我关闭服务器时我仍然可以在端口 80 上获得 404。所以我当时想这到底是怎么回事。我决定重新启动我的路由器,就像变魔术一样一切正常。不知何故 222.222.222.222 正在访问路由器而不是服务器。这是尽管端口 80 被转发到我路由器上的服务器。不确定路由器如何决定不转发它并尝试自行处理它。
每当我向 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 - Not Found
向我的 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;
}
}
}
我在 nginxmydomain.conf 文件中的配置
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 的东西的问题。我唯一使用的其他东西是 pm2 和使用 express 的 nodejs。会不会是我的 Ubuntu 服务器有问题?我也为服务器做了端口转发,但没有成功。
我有 运行 命令 sudo nc -l 80 和 运行 跨越一些奇怪的东西。当我转到 chrome 中的 IP 地址(不是真实地址)222.222.222.222 时,我没有得到任何响应;但是,当我点击 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 以外的任何其他端口访问域时,因此在我的情况下 443 用于 https 它有效。我假设每个端口都可以工作,但出于某种原因端口 80。
可能与ubuntu防火墙有关,您可以尝试使用命令行允许访问该端口
sudo ufw allow 4000/tcp
我的天哪!
看起来当我关闭服务器时我仍然可以在端口 80 上获得 404。所以我当时想这到底是怎么回事。我决定重新启动我的路由器,就像变魔术一样一切正常。不知何故 222.222.222.222 正在访问路由器而不是服务器。这是尽管端口 80 被转发到我路由器上的服务器。不确定路由器如何决定不转发它并尝试自行处理它。