1. 💬
-
Forward proxy: If there is no way to access Google.com in China, we can access a server Z that can access Google.com. Let the server Z access Google.com and return the content of Google.com to us. This server Z is called a proxy server.
-
Reverse proxy: when we go to visit baidu.com, baidu will beat this request to a server on Z [in order to access speed or reduce the financial burden on the server what 】, again by Z to forward our request to the server we don’t know which target server, the server Z is known as a reverse proxy server, similar to the station.
⏬ install Nginx
- Install on a Linux server
yum -y install gcc yum install -y pcre pcre-devel yum install -y zlib zlib-devel yum install -y openssl openssl-devel 【 use HTTPS is need to download the two packages 】 wget http://nginx.org/download/nginx-1.17.10.tar.gz according to its own needs installation specified version 】 【 tar - ZXVF nginx - 1.17.10. Tar. Gz CD /usr/local/nginx/ sbin/. /nginx/ usr/local/nginx/ sbin/. /nginx -s Reload [reload]./nginx -s stop [stop]Copy the code
Ps1: If the port is occupied, modify the nginx listener port and reload it.
Ps2: nginx configuration file is in /usr/local/nginx/conf
- Install in server with Docker
docker search nginx docker pull nginx:latest docker images docker run --name mynginx -p 12306:80 -d nginx Start a container named mynginx and map the local 12306 port to port 80 inside the container.Copy the code
Ps1: Configure a 12306 portal in the security group of the server [visit http://[server IP]:12306]
Ps2: Docker needs to enter the container to view the configuration, run the docker exec -it [id] bash command, generally there is no vim command in the docker container, you can run apt-get update && apt-get install vim. Generally, the configuration is in /etc/nginx
- Install on macOs
Brew search nginx brew install nginx nginx -v nginx -s reload nginx stop brew search nginx brew install nginx nginx -vCopy the code
If the port is occupied, modify the nginx listener port and reload it.
3. Configure 📒 nginx
Some configuration of Ngnix [relevant path changes according to their own substance]
# more configuration information for the http://nginx.org/en/docs/ user nginx; Worker_processes auto (worker_processes auto) worker_processes auto (worker_processes AUTO) # error_log /var/log/nginx/error.log; Pid: /var/run/nginx.pid: /var/run/nginx.pid # load dynamic module include/usr/share/nginx/modules / *. The conf # number of simultaneous connections: Events {worker_connections 1024; 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 path access_log/var/log/nginx/access. Log the main; The interpretation of the # sendfile & tcp_nopush & tcp_nodelay https://www.jianshu.com/p/cac0a92b9530 # is it allowed to upload files sendfile on; Tcp_nopush on tcp_nopush on tcp_nopush on tcp_nopush on Tcp_nodelay on: the kernel will wait for more bytes to form a packet to improve I/O performance. Gzip on; Keepalive_timeout 65; # Nginx uses a hash table types_hash_max_size 2048 to quickly process static data sets such as server names, mapping directive values, MIME types, and request header string names; Include /etc/nginx/mime.types; # default file type default_type application/octet-stream; "Upstream web{" ip_hash" = "ip_hash"; "ip_hash" = "ip_hash"; 127.0.0.1:8080: load balancing server 127.0.0.1:8080: load balancing server 127.0.0.1:8080 Server 127.0.0.1:8888 weight = 1; Add weight} # # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # loading modular configuration file, D: /etc/nginx/conf.d/*.conf: /etc/nginx/conf.d/*.conf: /etc/nginx/conf.d/*.conf: /etc/nginx/conf.d/*.conf: /etc/nginx/conf. # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a server corresponding to a web server # {# listen listen port 80 default_server; listen [::]:80 default_server; # server domain name server_name localhost; Root /usr/share/nginx/ HTML; # include /etc/nginx/default.d/*.conf; Location / {root HTML; index index.html index.htm; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # If client IP is required, this switch may be rewritten as reverse proxy IP proxy_redirect off; Proxy_set_header Hose $host; proxy_set_header Hose $host; # Proxy_http_version 1.1; # proxy_http_version 1.1 proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_cache_bypass $http_upgrade; Proxy_set_header x-real-ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; Proxy_connect_timeout 600; proxy_read_timeout 600; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }} # Configure HTTPS server {# make sure to use SSL flag, default port 443 listen 443 SSL; server_name work.com; ssl on; Ssl_certificate /etc/nginx/server.crt; Ssl_certificate_key /etc/nginx/server.key; Ssl_session_timeout 5m; location / { root /usr/local/web/; add_header 'Cache-Control' 'no-store'; }}}Copy the code
4. 🤓️ for the front-end Nginx
For the front end, we focus on the configuration in nginx.conf
Upstream web_router {server 123.123.123.123; } server{ listen localhost; location / { proxy_pass http://web_router; }}Copy the code
We only need to write the above two. Normally, the rest of the configuration will be done by operation and maintenance. They will use the include command to add the configuration we wrote to the overall configuration