AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1035559
Accepted
CybeX
CybeX
Asked: 2020-09-28 20:09:16 +0800 CST2020-09-28 20:09:16 +0800 CST 2020-09-28 20:09:16 +0800 CST

nginx 连接被远程拒绝,但 localhost 连接

  • 772

我的 Ubuntu Server 20.04 LTS 有一个奇怪的问题

背景简介:

我安装了 nginx 并且在设置letsencrypt时遇到了很多麻烦。尝试使用静态提供的文件进行此操作,它不断表示连接被拒绝。我恢复到原来的 nginx 默认配置,从 localhost 我看到 HTML 中的页面内容“欢迎使用 NGINX”,但是从多个外部来源,我不断收到连接被拒绝。

配置 默认NGINX配置(直接复制+粘贴)

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

        server_name _;
                try_files $uri $uri/ =404;
                # proxy_pass http://localhost:8080;
                # 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;
        }
}

使用 curl,我尝试从远程站点连接到端口 80:

curl http://my-domain.com

回应

curl: (7) Failed to connect to my-domain.com port 80: Connection refused

其他信息:

添加到启用站点的活动 NGINX 配置

blms@my-domain:/etc/nginx/sites-enabled$ ls -la
total 8
drwxr-xr-x 2 root root 4096 Sep 28 03:57 .
drwxr-xr-x 8 root root 4096 Sep 28 03:29 ..
lrwxrwxrwx 1 root root   34 Sep 28 03:57 default -> /etc/nginx/sites-available/default

Nginx 服务状态:活动(未报告错误)

blms@my-domain:~$ sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2020-09-28 03:57:26 UTC; 6min ago
       Docs: man:nginx(8)
    Process: 2901 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 2912 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 2913 (nginx)
      Tasks: 2 (limit: 1074)
     Memory: 2.6M
     CGroup: /system.slice/nginx.service
             ├─2913 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             └─2914 nginx: worker process

Sep 28 03:57:25 my-domain.com systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 28 03:57:26 my-domain.com systemd[1]: Started A high performance web server and a reverse proxy server.

已确认 HTTP Server 在端口 80 上侦听:

blms@my-domain:~$ sudo ss -tlp | grep http
LISTEN   0        511              0.0.0.0:http                  0.0.0.0:*       users:(("nginx",pid=2914,fd=6),("nginx",pid=2913,fd=6))
LISTEN   0        511                 [::]:http                     [::]:*       users:(("nginx",pid=2914,fd=7),("nginx",pid=2913,fd=7))

iptables 允许所有连接

blms@my-domain:~$ sudo iptables -L -v
Chain INPUT (policy ACCEPT 2936 packets, 238K bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 2567 packets, 393K bytes)
 pkts bytes target     prot opt in     out     source               destination

坦率地说,我很困惑。我也重启了也没用。

有什么建议么?

更新

使用 IP 地址卷曲

curl x.y.z.a:80
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:03 --:--:--     0
curl: (7) Failed to connect to x.y.z.a port 80: Connection refused

在服务器本身上卷曲 localhost

curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
ubuntu nginx ubuntu-20.04 lets-encrypt linode
  • 1 1 个回答
  • 3963 Views

1 个回答

  • Voted
  1. Best Answer
    CybeX
    2020-09-29T04:31:43+08:002020-09-29T04:31:43+08:00

    问题的原因是我自己的原因之一。

    问题是我没有刷新我的 NAT 表。我使用iptables -F -t nat. 这解决了问题。

    我将这个答案留在这里,希望它可以帮助其他人。

    • 2

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

  • VirtualBox 上 Ubuntu 的访客优化技巧 [关闭]

  • 外部硬盘上的 virtualbox 虚拟硬盘驱动器(Vista 主机上的 ubuntu 客户机)

  • 如何在 Ubuntu 上挂载 LVM 分区?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve