【问题标题】:Can't access nginx server in local network, android无法访问本地网络中的nginx服务器,android
【发布时间】:2018-09-09 13:40:15
【问题描述】:

我的问题是我的手机无法访问本地网络中使用 nginx 的服务器

我可以直接从我的机器访问它,也可以从 genymotion 模拟器访问它:

但我的安卓手机(7.1.2 N2G47H;Redmi Note 5A Build)无法加载。它一直卡在加载中,直到浏览器(Chrome 68.9.3440.91)说超出了响应时间。

我试图通过本地网络 (192.168.1.123) 中机器的 IP 访问服务器

但是,如果我使用 python 中的SimpleHTTPServer 模块提供文件,它可以正常工作,提供文件。

nginx.conf:

user tauyekel staff;
worker_processes auto;

events {
    worker_connections  1024;
}

http {
    include mime.types;
    default_type  application/octet-stream;

    sendfile on;
    keepalive_timeout  65;
    client_max_body_size 128M;

    gzip  on;
    gzip_comp_level 5;
    gzip_min_length 256;
    gzip_proxied any;
    gzip_vary on;

    gzip_types
    application/atom+xml
    application/javascript
    application/json
    application/rss+xml
    application/vnd.ms-fontobject
    application/x-font-ttf
    application/x-web-app-manifest+json
    application/xhtml+xml
    application/xml
    font/opentype
    image/svg+xml
    image/x-icon
    text/css
    text/plain
    text/x-component;

    server {
        listen *:80;

        # serve static files
        location ~ ^/.*$ {
            root /Users/tauyekel/Documents/webprojects/mobile-test;
        }
    }
}

我的静态文件目录由单个 index.html 组成:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Mobile Test</title>
</head>
<body>
    <h2>Tauka!</h2>
</body>
</html>

iOS 设备也不行

我将不胜感激,谢谢

【问题讨论】:

    标签: android nginx


    【解决方案1】:

    我不确定我是否正确理解了您的问题,但我想知道您的手机是如何连接到您的网络的?您的计算机通过以太网电缆或 wi-fi 连接到它。这会为其分配一个网络内的 IP 地址,并且可以解析连接。你的手机也用wi-fi吗?还是您只是打开浏览器窗口并输入 IP 地址?如果没有与本地网络的 wi-fi 连接,手机将使用手机提供商的网络连接来访问互联网。问题是您的计算机 IP 地址 192.168.1.123 是私有网络地址,无法从 Internet 访问。

    【讨论】:

    • 抱歉,如果不清楚,但是是的,我正在通过 wi-fi 连接到我的家庭网络。它适用于 python 简单服务器,但不适用于 nginx
    猜你喜欢
    • 1970-01-01
    • 2012-01-03
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 2020-02-24
    • 1970-01-01
    • 2023-03-17
    相关资源
    最近更新 更多