I'm trying to setup port forwarding from localhost to a local server using socat. The server is available via http://my-local-domain.
Here is what I tried:
socat -d -d tcp-listen:8081,reuseaddr,fork tcp:my-local-domain:80
When I open the browser and go to http://localhost:8081, I see my original localhost page, not the page when I navigate to my-local-domain.
How does one create port-forwarding to a local domain using socat?
I found that I'm not able to use Port 80 because the Host appears as localhost to NGINX, and so localhost serves the request [which would explain the original issue].
You can verify this by:
Opening nginx.conf
Adding ..."Host=$host"... to the log_format
Tailing the access logs [tail -f /usr/local/nginx/logs/access.log]
You'll notice that Host is always localhost, and so localhost serves the request.
The way to solve this is to change the Host info from localhost to my-local-server:
Localhost:8081 --> [change Host info] --> my-local-server:80
The way I found to do this was to create a proxy via Node.JS [as a go-between] as follows:
Create proxy.js
Copy the contents of the code from this gist and paste into proxy.js
Run the following command in the terminal to create proxy to web server:
PORT_LISTEN=8091 PORT_TARGET=80 HOST_TARGET="my-local-server" HOST_ORIGIN="my-local-server" node proxy.js
Run socat to proxy
socat -d -d tcp-listen:8081,reuseaddr,fork tcp:localhost:8091
So now we have the following:
Localhost:8081 --> Localhost:8091 --> my-local-server:80
This is what worked.
Related
I'm a newbie to Nginx. I cannot access my Node.js application that I deploy on AWS EC2 using Nginx reverse proxy. If I do curl http://localhost:3000 I can see the application is running successfully on the server(I'm using pm2 for running node server). But when I try to access it in my browser or postman using public DNS I get the error This site can't be reached and the request gets timeout. Here's my Nginx configuration (I have followed a number of tutorials for this)
The configuration file is named nginx.conf and is in /etc/nginx/sites-enabled directory. If I do sudo nginx -t it says syntax is ok and the test is successful. Also I can see the Nginx is running using command sudo systemctl status nginx What could be the possible reason for this behaviour?
I figured it out the problem wasn't with the Nginx configuration actually I needed to allow public access for port 80 on my ec2 instance which is blocked by default. I allowed port 80 and everything is working fine. This blog helped me. Visit it for me details on how to enable port 80 for your ec2 instance.
I am using Laradock to develop locally and so have an entry in the hosts file.
How can I get this working with ngrok?
I tried:
ngrok http -host-header=site.test 80
(https://helgesverre.com/blog/expose-local-webserver/)
but get: Failed to complete tunnel connection
(site.test works)
I got this working by running ngrok on the host machine instead of the container.
I have next setup:
Local host - my work PC
Project VM - Vagrant box with project files, runned on my work PC
Remote host - remote PC, from which I need to access hosts on Project VM
Project VM setup (/etc/hosts on Local host):
192.168.100.102 host1.vm.private
192.168.100.102 sub1.host1.vm.private
192.168.100.102 sub2.host1.vm.private
"host1" subdomains resolved by application router and served by nginx (config for "host1.vm.private" on Project VM):
server {
listen 80;
server_name ~^(.+\.)?host1\.vm\.private$;
...
}
I need to make "sub(1|2|N).host1.vm.private" reachable from remote host. How this can be done?
So, i found the solution: Trouble SSH Tunneling to remote server
The main issue is that invalid HTTP header was sent and nginx cant resolve a virtual host.
Run on local PC ssh -R 8888:192.168.100.102:80 <remote_pc_credentionals>. Or, run "inversed" command with ssh -L flag on remote PC.
Add "sub1.host1.vm.private" to /etc/hosts on remote PC: 127.0.0.1 sub1.host1.vm.private
OR
Send "Host" header with each request: curl -H "Host: sub1.host1.vm.private" "http://localhost:8888/some/path"
Objective: want to share a website preview using ngrok, which creates a tunnel from which my localhost can be seen with an url of something like mywebsite.ngrok.io
Problem: I use WAMP and my localhost folder looks something like this:
localhostdirectory
|-- website1
|-- website2
|-- etc
To access a website I type to localhost/website1/ in the browser, I would like to tunnel only that URL, the possible solutions would be:
Setting up a Virtual host, I would go through the hassle of manually setting up a virtual host, then I get something like website1.dev, and then I would pass it to ngrok as the host header in the HTTP request, like that:
ngrok http -host-header=website1.dev 80
I didn't understand what the host header is though, and why can't I pass a relative url like localhost/website1/, also what is the rewrite option?
Change the folder directory of my localhost to the folder of the website, I would prefer not to do that.
Is there a better way to accomplish my objective in an easier way, maybe going through WAMP aliases?
If you make do with Apache Vhost you just have to exec command
ngrok http -host-header=rewrite YOUR-LOCAL-DOMAIN:PORT
Dont forgot to edit host file for resolution #IP <-> YOUR-LOCAL-DOMAIN
I tried below way.
When I ran $ ./ngrok http 80 ngrok listen to localhost:80 which shows dashboard because apache server is running on port 80. Then I tried running subfolder in another port, which solved problem. Assume you have project in xyz and want ngrok should points it. Then do following
$ cd /opt/lampp/htdocs/xyz
$ php -S localhost:8080
Here 8080 is any unused port. localhost:8080 direct points to xyz and then open other terminal
$ ./ngrok http 8080
By doing this ngrok will listen to 8080 port were your xyz is running.
Hope this helps!!
After you set up the ngrok address to point to localhost on port 80, you can access your websites by their names.
Ex:
ngrok http -subdomain=dev 80
Access website1:
dev.ngrok.io/website1
I believe the correct syntax now for ngrok v3 is ngrok http --host-header=rewrite YOUR-LOCAL-DOMAIN:PORT
Notice the double --
https://ngrok.com/docs/guides/upgrade-v2-v3
I have Nginx running on 8080, while Varnish runs on port 80. I can do
wget localhost:8080
in shell and get a response, but if I run
wget localhost
I get connection refused. For reference, I'm trying to access it externally but get the same problem. Hopefully I can solve access from localhost first!
Thanks in advance!
netstat -tulnp shows you every port and service running
iptables -L shows you if port open or blocked
cheers