how to proxy exp://127.0.0.1:19000

(moving this over from Github issues how to proxy exp://127.0.0.1:19000 · Issue #1200 · expo/expo-cli · GitHub )

Hello everyone, I installed docker on the server, and run expo in docker. I also configured nginx proxy 19000 port on the server, but the expo client can’t access it. What do I need to do?

Can you give some more information?

What is the proxied URL you have? Is your web browser able to access that URL? What about the web browser on your phone?

(You can replace exp:// with http or https depending on how you’re doing you’re proxy to test opening from web browser).

I have solved this problem. The specific configuration of nginx is as follows.

It should be noted that the IP of docker container needs to be converted when it is passed as url parameter. For example, 10.32.0.23 needs to be changed to 10_32_0_23.

The full url is http://10_32_0_23.exp.mydomain.com

server {
    listen 19001;
    server_name  *.exp.mydomain.com;

    if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+\.[^\.]+)$) {
        set $ipstr $1;
    }

    root   /var/www/html/auth;
    index  index.html;

    error_page  405     =200 $uri;

    location / {
      default_type 'text/html';
      set $target '';

      access_by_lua_block {
        if (ngx.var.ipstr ~= nil) then
          local ip = (string.gsub(ngx.var.ipstr,"_","."));
          ngx.var.target = ip .. ':19001';
        else
          ngx.say('deny');
        end;
      }

      proxy_pass http://$target;
      proxy_http_version 1.1;
      proxy_set_header Host $http_host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
    }
}


server {
    listen 19000;
    server_name  *.exp.mydomain.com;

    if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+\.[^\.]+)$) {
        set $ipstr $1;
    }

    root   /var/www/html/auth;

    location / {
      default_type 'text/html';
      set $target '';

      access_by_lua_block {
        if (ngx.var.ipstr ~= nil) then
          local ip = (string.gsub(ngx.var.ipstr,"_","."));
          ngx.var.target = ip .. ':19000';
        else
          ngx.say('deny');
        end;
      }

      proxy_pass http://$target;
      proxy_http_version 1.1;
      proxy_set_header Host $http_host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
    }
}


server {
    listen 19006;
    server_name  *.exp.mydomain.com;

    if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+\.[^\.]+)$) {
        set $ipstr $1;
    }

    root   /var/www/html/auth;

    location / {
      default_type 'text/html';
      set $target '';

      access_by_lua_block {
        if (ngx.var.ipstr ~= nil) then
          local ip = (string.gsub(ngx.var.ipstr,"_","."));
          ngx.var.target = ip .. ':19006';
        else
          ngx.say('deny');
        end;
      }

      proxy_pass http://$target;
      proxy_http_version 1.1;
      proxy_set_header Host $http_host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
    }
}

Hi @soitun

Thanks for posting this.

Would you mind adding ``` on a line above and below the config so that it is all shown in one “code” block in your post?

In your “full url” example, are you not missing .exp in there just after the converted IP address?

Also, while the above will work most of the time, just bear in mind that if one of those ports is already in use when you run expo start, expo will choose the next available port.

1 Like

Sorry, it’s my carelessness. It has been corrected. the full url is http://10_32_0_23.exp.mydomain.com

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.