How to do port forward on a VPS? - networking

I have a VPS on Ubuntu 13.10 x86_64 it has an:
public IP: say 1.1.1.1
private IP: 198.168.1.33
and I want to redirect all my incoming traffic to port 443 to my private IP 198.168.1.33
I have only SSH access to the server, can anyone tell me the command to do it? Thx.

The easiest way would be to use Apache and either
Setup a virtual host - see Examples
OR
Use Apache Proxy

Related

How can I modify my IP address on my localhost in MAMP?

Developing a plugin for WordPress locally I'm wanting to implement Akismet in form validation but I'm required an IP address with the submission and when I run:
function check_ip_address() {
if (isset($_SERVER['REMOTE_ADDR'])) :
$ip_address = $_SERVER['REMOTE_ADDR'];
else :
$ip_address = "undefined";
endif;
return $ip_address;
}
echo check_ip_address();
I get back a ::1. When I researched to resolve this I didn't find a solid answer from:
Ask Different tag MAMP
How do I rename MAMP web server?
When researching how to resolve ::1 I found Should a MAMP return ::1 as IP on localhost? that suggests a sudo of:
sudo vi /etc/apache2/httpd.conf
So I go to MAMP/conf/apache/httpd.conf and try to modify line 48 from Listen 8888 to Listen 127.0.0.1 and I get an error and Apache will not restart. How can I modify my MAMP IP so I can get a proper IP from $_SERVER['HTTP_USER_AGENT']?
It's ::1 because that's the IPv6 loopback address, equivalent of 127.0.0.1, and the remote address is yourself as MAMP is running locally, the remote browser is on the same machine.
REMOTE_ADDR represents the IP the request came from. In most scenarios this is the same as the IP the browsers machine has on the open-internet, but here MAMP is running Apache natively so it's 127.0.0.1 or ::1. If you were using a docker container or a Virtual machine, it would be a private IP on a range specified when configuring your containers/VMs.
So to retrieve the IP you're expecting, you'll need to use an external service, or, for the sake of debugging, pass Akismet a hardcoded IP, but I suspect it's asking for the IP of whomever is commenting.

How to port forwarding/tunneling TCP on Nginx

I am using nginX
nginx version: nginx/1.4.6 (Ubuntu)
I have an app listening TCP on IPv4 port besides 80.
How I can to proxy/forward from domain on TCP 80 to this port.
What keywords should I find or nginx configurations?
Thanks
I think what you need is reverse proxy
Here is great tutorial how to forward connection from nginx to apache
This tutorial shows how to forward connection from nginx on port 80 to apache on port 8080
There are some options:
You can use ssh-forwarding:
plink <ssh user>#<server_ip> -pw <ssh pass> -L 0.0.0.0:<external port>:<target ip in internal network>:<target port in internal network>
Create VPN by OpenVPN for example
Check here - https://unix.stackexchange.com/questions/290223/how-to-configure-nginx-as-a-reverse-proxy-for-different-port-numbers

Vagrant forward port 8080 to 80

So I have a NGINX server listening on port 8080 with uwsgi on Vagrant box. The config.vm.forward_port 8080, 80 is not working for me. I know that it's recommended to forward on ports higher than 2000, but I need the 80. Is there any issue for that?
I'm using vagrant for development, but I need to make some tests from outside using my domain name on port 80.
Thanks for your help.
When trying to forward ports to less than 1025 vagrant gives me following message which you might have missed:
You are trying to forward to privileged ports (ports <= 1024). Most
operating systems restrict this to only privileged process (typically
processes running as an administrative user). This is a warning in case
the port forwarding doesn't work. If any problems occur, please try a
port higher than 1024.
I was using port forwarding to same port with following configuration:
config.vm.forward_port 80, 80
And then run vagrant up, but when trying curl localhost, it wasn't able to connect to host. But when running vagrant as sudo user sudo vagrant up, then I was able to access the port from my host.
is port 80 available i.e. if you run netstat -an | grep 80, does it show in the list as already being used by another process? Is uwsgi added to the module list of nginx (and did you run make/make install on it)? Have you tried checking if you need to use higher privilenges (perhaps try running as sudo).

browser in host can not see vagrant box, portforward does not work

I have installed Vagrant in my Window XP, and in my Vagrantfile I have:
Vagrant::Config.run do |config|
# Setup the box
config.vm.box = "lucid32"
config.vm.forward_port 80, 8080
config.vm.network :hostonly, "192.168.10.200"
end
But I see no sign of my vagrant box when I type "http://192.168.10.200:8080" in browser.
IP address of the virtual box is correct, because from within the vbox, I have:
vagrant#lucid32:~$ ifconfig
....
eth1 Link encap:Ethernet HWaddr 08:00:27:79:c5:4b
inet addr:192.168.10.200 Bcast:192.168.10.255 Mask:255.255.255.0
There seem to be no firewall problem because if I type
vagrant#lucid32:~$ curl 'http://google.com'
it works fine.
I have read Vagrant's port forwarding not working
and tried:
vagrant#lucid32:~$ curl 'http://localhost:80'
curl: (7) couldn't connect to host
and also
vagrant#lucid32:~$ curl 'http://localhost:8080'
curl: (7) couldn't connect to host
So, looks like port forward is not working...
If you know what I can do so I can access my vbox from host browser, can you help me?
Thanks in advance
If you just started a Vagrant box with this Vagrantfile, there is nothing more than an empty Ubuntu Lucid, which does not run any service yet. So there is nothing served on port 80, this is why there is nothing to see either from inside the box on port 80 or the host machine on 8080.
For you Vagrant machine to provide some services (such as a web server on port 80), you have to do some provisioning. You can do it manually or using Chef or Puppet which are hooked into Vagrant's up process.
I had a similar problem. Sometimes using port forwarding for ports below 2000 is a problem. What worked for me is choosing ports that are above 2000. So my vagrantfile now looks like:
config.vm.network :forwarded_port, host: 4500, guest: 9000
Typing localhost:4500 on my host machine now just works fine. It seems like you are on an older version of vagrant than mine, so you can edit your vagrant file to something like
config.vm.forward_port 9000, 4500
Now typing localhost:4500 on your host machine should work fine.
Good luck,

Connect to nginx (VirtualBox, Fedora) from Windows host

Fedora in VirtualBox running django dev server (bound to 0.0.0.0:8000) and nginx (listening to port 90)
I have NAT connection set up for the VM and port forwarding 8000 -> 8000, 8001 -> 90
I can see django as 127.0.0.1:8000
But no response from 127.0.0.1:8001
Any ideas?
Dumb question: Can the Fedora guest connect OK to nginx running locally?
Not so dumb question: Have you used tcpdump/wireshark/smartsniff or a similar tool to see if the traffic is making it through the host->guest at all? perhaps the Fedora firewall is blocking non-local connections to port 90?
Also, why not just add a "Host Only" second network adapter to the Fedora guest and forget about fiddling with the NAT settings?

Resources