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?
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;
}
}
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.