Ngrok/nginx two ways of intranet mapping to external network environment

Source: Internet
Author: User
Tags server port

Ngrok Intranet Mapping to extranet environment

1, download Ngrok, URL: https://ngrok.com/download

2, registered Ngrok, address: Https://dashboard.ngrok.com/user/signup

If you already have Ngrok account number, log in Ngrok, as shown in the figure to find your Authtoken

3, will download a good ngrok to the local, into the directory where Ngrok

4, will Authtoken (such as 40u6g ...). Added to the local (only the first time you need to perform the add, you don't need to add it later.) The author is the MAC environment)

./ngrok Authtoken 4ou6g ....
5, Start Ng rok, the mapped port is 8080

./ngrok http 8080
Execute the above launch command, session Status=online that represents the success, can be based on the automatic generation of domain name access, such as the author generated domain name is: Http://48b1c3e2.ngrok.io

Note: Because Ngrok free version, domain name is not fixed, if you want to stabilize the domain name, you need to pay, no longer narrated.

Here is a nginx through the external network mapping, fixed domain name, free version, if you have to have a public network IP

nginx Map Extranet Environment

1, need to install nginx, if not yet installed NGINX,MAC environment How to install Nginx can refer to this blog,

http://blog.csdn.net/lanqibaoer/article/details/72853056

If Nginx is already installed, but it is not clear Nginx installation directory, you can query by executing the following command:

Ps-ef | grep nginx
/usr/sbin/nginx-t
[Root/]# Ps-ef | grep nginx
Root      9730     1  0  2017?        00:00:00 nginx:master process/usr/sbin/nginx
root     14290 14218  0 09:34 pts/5 00:00:00    grep--color= Auto Nginx
nginx    32480  9730  0  2017?        00:01:46 nginx:worker process
nginx    32481  9730  0  2017?        00:02:20 nginx:worker Process
[root/]#/usr/sbin/nginx-t
nginx:the Configuration nginx.conf syntax are OK
nginx:configuration file/etc/nginx/nginx.conf test is successful
"The configuration file/etc/nginx/nginx.conf syntax is OK" here/etc/nginx/nginx.conf is the address of the Nginx configuration file installed in your server.

2, there is a public network server, in the public network server nginx.conf add the following content

Upstream Tunnel {
  server 127.0.0.1:7689;
}

server {
  listen;
  server_name dev.ninghao.net;
  
  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://tunnel
  }
}
Above with NGINX created an agent, if someone visit the Dev.ninghao.net,nginx will transfer the request to tunnel, this tunnel refers to the public network server, the port number is 7689, in a moment we want to use this port to communicate with the intranet environment computer.

Note: 1 upstream and server can be configured multiple, each upstream and server are peers;

2 server listen can not be the same (here need to be discussed), if the listen port is 80, the default domain name access to the port is 80, without the explicit indication, if the listen port is 80 other than the port, for example, 8088, then access to the domain name and then add 8088, such as HTTP ://dev.ninghao.net:8088/

3, open your intranet environment of the server

We're going to use SSH to open a channel between the local computer and the public network server. The commands to be executed in the intranet environment server are like this:

Ssh-vnnt-r server port: localhost: Local port server username @ Server IP Address
Example:
Ssh-vnnt-r 7689:localhost:3000 root@42.120.40.68
In the example above, 7689 refers to the port of the public network server, and the next 3000 of the localhost is the port used by the local computer.

Root is the user who logs on to the public network server, 42.120.40.68 is the IP address of the public network server.

Because we have configured the NGINX of the public network server, access to dev.ninghao.net, transfer the request to the server on the 7689 port,

This port is connected to the 3000 ports on our intranet environment computer.

So, the server that you build on the intranet development environment, should use 3000 this port to provide the service.

That is, when someone visits dev.ninghao.net this address, the user gets the response is provided by the server on your intranet development environment.

Reference Documentation:

Https://ngrok.com/docs

http://blog.csdn.net/liuxiyangyang/article/details/22922265/

https://ninghao.net/blog/4452

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.