兄弟们我又来了,有个问题又搞不懂了,帮帮我这个菜鸟吧

288 天前
 z8596007
server {
    listen 80;
    listen [::]:80;
    server_name xxx.xxx.xxx;
    return 301 $host$request_uri;
}
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name xxx.xxx.xxx; 

    ssl_certificate   /etc/nginx/ssl/xxx.xxx.xxx.pem;
    ssl_certificate_key    /etc/nginx/ssl/xxx.xxx.xxx.key; 

    location  / {
        proxy_pass http://172.20.0.7:4000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-Proto  $scheme;

        add_header X-Cache $upstream_cache_status;

        proxy_set_header Accept-Encoding "";
        sub_filter "http://" "https://";
        sub_filter_once off; 
    } 
} 

nginx 配置如上 现在的问题是 nginx 容器内可以访问 http://172.20.0.7:4000 ,宿主机也可以访问 172.20.0.7:4000,使用服务器 ip:4000 也可以访问这个容器,但是使用域名:https://xxx.xxx.xxx 就提示花了太长时间进行响应 443 端口也映射了。 不知道是什么问题了。。太难了。

1570 次点击
所在节点    问与答
23 条回复
linauror
288 天前
先记下 nginx 访问日志,看有没有访问到 nginx ,或许是安全组的 443 端口没开?
poporange
288 天前
你先看看 你防火墙开 443 端口了么
vacuitym
288 天前
需要查看 ng 日志
z8596007
288 天前
@linauror
```
400 Bad Request
The plain HTTP request was sent to HTTPS port
nginx/1.21.5
```
直接访问服务器:443 提示这个。
z8596007
288 天前
@poporange
400 Bad Request
The plain HTTP request was sent to HTTPS port
nginx/1.21.5
直接访问服务器:443 提示这个。
z8596007
288 天前
@vacuitym
ng 日志中没有啥东西。。
2023/07/26 06:11:50 [notice] 47#47: signal process started
2023/07/26 06:13:55 [notice] 50#50: signal process started
就启动时的
cslive
288 天前
return 301 https://$host$request_uri; # 重定向到 https
xulianbang
288 天前
cf 开了小黄云的话,到 ssl 里加蜜方式设置为完全
Nginx 改配置记得重新加载
好像遇到过此问题,记不清了,你试试
kosmgco
288 天前
http://xxx.xxx.xxx:443 是这样访问的吗?
LxnChan
288 天前
你 nginx 是怎么装的,也在容器里吗
brader
288 天前
云防火墙开了 443 没
z8596007
288 天前
@LxnChan 是在容器里的
z8596007
288 天前
@cslive 改了 没啥效果
z8596007
288 天前
@brader 开了的
z8596007
288 天前
@xulianbang 不是走的 cf ,
vacuitym
288 天前
@z8596007 error 和 info 日志都没东西吗,要是都没得话说明都没到 ng ,可以看下域名解析之类的
z8596007
288 天前
@vacuitym 没有。域名解析是到这个服务器的
kokutou
288 天前
@z8596007
域名 http 加 s 了没有。。。
vacuitym
288 天前
@z8596007 不然你直接用服务器的外网 ip:443 请求下试试 ng 能不能收到,如果能的话就说明域名解析问题,如果不能 ng 的监听就有问题
z8596007
288 天前
@vacuitym 可以收到。
返回的是
400 Bad Request
The plain HTTP request was sent to HTTPS port

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/959908

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX