Y
Y
yury_borisov72016-12-10 13:02:25
linux
yury_borisov7, 2016-12-10 13:02:25

How to set up a tunnel (Proxying from vds to localhost)?

Hi all
, this is a question. There is an android application that I’m developing now, I’m testing it on my device,
I’m making an api that is on localhost, I can’t connect to my computer’s localhost from my device, so I was advised to make a tunnel
I bought vds installed nginx, I bought a domain
here are the nginx settings for the domain

upstream domain {
  server 127.0.0.1:3001;
}
server {
  listen 80;
  server_name domain.ru;
  
  location / {
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://domain;
  }
}

127.0.0.1	localhost 
127.0.0.1 domain.loc

this is on my PC in the file /etc/hosts
then through the terminal on my home PC I connect
ssh -vnNT -R 3001:domain.loc:80 [email protected]
here is the log
d
ebug1: Authentication succeeded (password).
Authenticated to domain.ru ([IP_Сервера]:22).
debug1: Remote connections from LOCALHOST:3001 forwarded to local address domain.loc:80
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: remote forward success for: listen 3001, connect domain.loc:80
debug1: All remote forwarding requests processed

I open a browser, go to domain.ru which one I bought and set it to look at my server,
and I get the nginx start page "Welcome to nginx!"
if I press ctrl + c in the terminal and then go to my domain again, I will get a 502 error (it's clear why)
so the question is why I see "Welcome to nginx!" and not what I have on the locale in domain.loc

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-12-10
@yury_borisov7

If I understand everything correctly, then try replacing proxy_set_header Host $http_host; Or write in
your home nginx instead of (or in addition to) domain.loc - domain.ru
The bottom line is that your home server receives a request like

GET / /HTTP1.1
Host: domain.ru

And home nginx, if I understand correctly, has a setting
server_name domain.loc;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question