Prospect: This article mainly introduces how I use NGINx with FRP to do multiple service Intranet penetration

You can check out my other article on FRP configuration setting up FRP and Service Registration (server and client)

Nginx features

Nginx

Engine X is a high-performance HTTP and reverse proxy Web server that also provides IMAP/POP3/SMTP services. Nginx was developed by Igor Sesoyev for the second most visited rambler.ru site in Russia (р а блер), the first public version 0.1.0 was released on 4 October 2004.

It distributes source code under a BSD-like license and is known for its stability, rich feature set, sample configuration files, and low consumption of system resources.

Nginx is a lightweight Web/reverse proxy server and E-mail (IMAP/POP3) proxy server distributed under the BSD-like protocol. It is characterized by less memory and strong concurrency. In fact, NGINx’s concurrency is better in the same type of web server

What can Nginx do

  1. The reverse proxy
  2. Load balancing
  3. HTTP server (static and dynamic separation)
  4. Forward agent
  5. The web service

Three, installation (this blog is only about installation, service registration will be another blog)

1. How to install Nginx in AMD64

There are two schemes, scheme two: use docker installation, Docker pull nginx, the subsequent is the container related configuration, this blog only tells about scheme one, scheme two will write another article to introduce

There are a lot of articles on the web about solution 1. Here I use the rookie tutorial -Nginx installation and configuration.

2. How to install nginx in raspberry PI

Install Nginx

sudo apt-get install nginx

Start the Nginx

sudo service nginx start

3. Ali cloud

Start the Nginx

systemctl start nginx.service

4. Frp and Nginx client server configuration

  • The client

1. Configure frPC. ini on the client

[common] server_addr = XX.xx.xx. xx(public IP address) server_port = 20084 token = 123456 [SSH] type = TCP LOCAL_IP = 127.0.0.1 Local_port = 22 remote_port = 6000 [dashboard] Docker Service) type = HTTP local_port = 4001 custom_domains = dashboard.xxx.com [blog] Docker service) type = HTTP local_port = 9000 custom_domains = blog.xxx.com Golang service) type = HTTP local_port = 4002 Custom_domains = phone.xxx.com Docker service) type = HTTP local_port = 8000 custom_domains = biji.xxx.com Vue-dist package) type = HTTP local_port = 8015 custom_domains = ui.xxx.comCopy the code

The client nginx. Conf

user www-data; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; }Copy the code

The client/etc/nginx/conf. D/UI. Conf

server { listen 8015; Server_name 192.168.1.2 instead. (Client host address) access_log off; index index.html index.htm index.php; root /var/www/html/ui; location /{ proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_connect_timeout 60; proxy_read_timeout 600; proxy_send_timeout 600; }}Copy the code

This client nginx configuration is complete

  • The service side

1. Configure frps.ini on the server

[common]
bind_port = 20084
vhost_http_port = 6000
token=123456
max_pool_count = 100
Copy the code

The service side nginx. Conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
         listen       80 default_server;
         listen       [::]:80 default_server;
         server_name  _;
         root         /usr/share/nginx/html;

         # Load configuration files for the default server block.
         include /etc/nginx/default.d/*.conf;

         location / {
         }

         error_page 404 /404.html;
         location = /404.html {}

         error_page 500 502 503 504 /50x.html;
         location = /50x.html {}
     }
}
Copy the code

Server /etc/nginx /conf.d/ This directory should contain the configuration file of the corresponding client service

dashboard.conf blog.conf phone.conf biji.conf ui.conf
Copy the code

Give an example of dashboard.conf

server { listen 80; server_name dashboard.xxx.com; access_log off; index index.html index.htm index.php; Vhost_http_port = 6000 proxy_pass http://127.0.0.1:6000/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_connect_timeout 60; proxy_read_timeout 600; proxy_send_timeout 600; }}Copy the code

At this point, the server configuration is complete

Nginx works with FRP to perform Intranet penetration and domain name access for multiple services.

The premise is that you must have a registered domain name, and complete domain name resolution.

If you have any questions, please leave a message

Nginx installation and reverse proxy – can be used with FRP – end of article, original is not easy, thank you for browsing!