You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native真机无法通过互联网访问Nginx代理的Spring Boot服务

问题:React Native真机无法访问部署的Spring Boot后端接口
  • 服务器部署了运行于8080端口的Spring Boot后端,搭配Nginx与SSL证书,路由器已转发80、443端口,No-IP的DDNS服务正常工作。
  • 开发React Native + Expo移动端应用时,通过浏览器调用后端接口完全正常,但真机调用仅返回网络错误,例如访问图片地址https://prieskumnici-is.ddns.net/api/img/bg/default/day.jpg或接口https://prieskumnici-is.ddns.net/api/api/background均失败。
  • 本地模拟器通过http://192.168.1.35:8080/...访问后端接口正常,且这些接口在Angular网页中也能正常使用。
  • Nginx和后端拦截器均未记录到真机的请求日志,推测问题出在Nginx或Spring Boot的配置上。已验证真机访问其他外部API和图片正常,例如https://www.prieskumnici.sk/assets/img/banner_zbor.png。
  • 更新:配置Nginx将80端口代理到后端后,模拟器可通过http://prieskumnici-is.ddns.net/api/img/bg/default/day.jpg访问图片,但真机仍无法访问。

相关配置代码

Nginx配置

http {
  client_max_body_size 500M;

  server {
    listen 443 ssl;
    server_name prieskumnici-is.ddns.net localhost;

    ssl_certificate C:/nginx/ssl/prieskumnici-is.crt;  # Path to your SSL certificate
    ssl_certificate_key C:/nginx/ssl/prieskumnici-is.key;  # Path to your SSL private key

    large_client_header_buffers 4 8096k;

    location /api/ {
      proxy_pass http://localhost:8080; 
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location / {
      root "C:\Users\Singi\Desktop\prieskumnici\prieskumnici-ui\dist\prieskumnici-ui";
    index index.html index.htm;
      try_files $uri $uri/ /index.html;
    }

    types {
      text/html                                        html htm shtml;
      text/css                                         css scss;
      text/xml                                         xml;
      image/gif                                        gif;
      image/jpeg                                       jpeg jpg;
      application/javascript                           js mjs;
      application/atom+xml                             atom;
      application/rss+xml                              rss;
    }
  }
}

React Native代码

return <ImageBackground source={{uri: "https://prieskumnici-is.ddns.net/api/img/bg/default/day.jpg"}} resizeMode="cover" style={{height: '100%'}}>
          <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
            <Text>Home</Text>
          </View>
       </ImageBackground>

内容的提问来源于stack exchange,提问作者Tomáš Singhofer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 22:26:26