The introduction

In order to run the small demo of self-test on the external network, which involves the two services of the front and back end, NatApp only bought a domain name and tunnel. In short, in order to save money, the method of using NatApp with Nginx was studied.

natapp

  • Apply for account

Go to the official website and register.

  • Buy the tunnel

Without big requirements, 9 yuan/month is enough for personal use.

  • Purchase secondary domain name

The secondary domain name is configured based on the local configuration, including the mapped address and port of the local computer and the purchased tunnel.

  • download

Then go to the client to download the corresponding version.

  • configurationconfig.ini

In the same directory as the natapp download, download the config.ini file, or simply copy the following content into the new config.ini file. You only need to configure authToken.

# Place this file in the same directory as NatApp and the program will read the [default] segment
# The same parameters in command line argument mode such as natapp-authToken = XXX will override this configuration
The command line argument -config= can specify any config.ini file
[default]
authtoken= * *Authtoken for a tunnel
clienttoken=                    # ClientToken of corresponding client will be ignored, if there is no authToken, please leave blank.
log=none                        None = no record,stdout= direct screen output, default to None
loglevel=ERROR                  The default log level is DEBUG
http_proxy=                     The proxy Settings, such as http://10.123.10.10:3128, must be left blank for non-proxy users
Copy the code
  • run

Command line tool CD natapp directory, and enter./natapp to start the service. In this case, you can access the local service by opening the corresponding domain name address.

nginx

  • download

Go to the download address and find a version to install. On MAC, run brew info nginx to install.

  • Check whether the installation is successful

Enter nginx on the terminal to start the service, and enter localhost on the console (the default port for unconfigured nginx.conf is 80). If the nginx official website is displayed, the installation is successful.

  • configurationnginx.conf

Go to the nginx installation directory and open the nginx.conf file. MAC, the movement of the terminal open/usr/local/Cellar/nginx can open the nginx installation directory, run here cat/usr/local/etc/nginx/nginx. Conf open the configuration file, the configuration is as follows:

# nginx 80 port configuration (listen a secondary domain) server {listen 80; server_name phoenixhg.natapp1.cc; Location / {proxy_pass http://localhost:9000; index index.html index.htm; } location /socket. IO / {proxy_pass http://localhost:3001; Proxy_set_header Host $http_host; Proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }}Copy the code

Listen listens to our port. My front-end project port is 80, so port 80 is used. Server_name points to our previously configured NatApp domain name. For example, the service address of my front-end project is localhost:9000, and that of the back-end is localhost:3001. Configure it through proxy_pass, save it and restart the nginx service (nginx -s reload). In this case, go to phoenixHg.natApp1. cc to view the IP address of the front-end deployment project. Front end request API address can change by domain access phoenixhg. Natapp1. Cc/socket. IO /.

IO /socket. IO /, and the socket proxy must be configured to support the above four lines of code.

You’re done

Non-lan access to your own projects now!