Reverse proxy, load balancing, high availability, and static/static separation

Ps - ef | grep nginx nginx processCopy the code

Nginx operation command

Switch to the nginx/sbin directory to check the usage of port 3000Copy the code

Netstat apn | grep to check the version number nginx – 3000 v

Stop nginx nginx -s stop

Start the nginx. / nginx

Reload nginx nginx -s reload Nignx cannot be accessed

Step 1: Configure the firewall for port 80:

Firewall-cmd –zone=public –add-port=80/ TCP –permanent

systemctl restart firewalld.service

Firewall -cmd –add-port=8080/ TCP –permanent firewall-cmd –reload View the firewall-cmd –list-all port that is opened to the outside world

If the firewall fails to start, run the systemctl start firewalld command to start the firewall. If no prompt is displayed, the firewall is successfully started. To disable firewall Settings, run the systemctl stop firewalld command to disable the function.

Setting a Reverse Proxy

Setting location in the SERVER block sets the property proxy_pass to the proxy addressCopy the code

Load balancing

110: added upstream myServer {server domain: port; Server domain name: port; } server { listen80; Server_name domain; location / { proxy_pass http://myserver;This name corresponds to the one above}} Load balancing mode1, polling (default)2Upstream myServer {server domain name: port weight=10; Server domain name: port weight=12;
}
3Hash each request is based on the access IP addresshashUpstream myServer {ip_hash; upstream myServer {ip_hash; Server domain name: port weight=10; Server domain name: port weight=12;
}
4Fair (third party) allocates requests based on the response time of the back-end server, and priority should be given to those with shorter time. Upstream myServer {server domain name: port weight=10; Server domain name: port weight=12;
	fair;
}
Copy the code
High availability

Keepalivedyum install Keepalived-y Conf file keepalive. conf. Start systemctl start keepalive. service keepalive. conf

Vrrp_script chk_http_port{script "/usr/local/src/nginx_check.sh" Interval 2 #(check script execution interval) weight 2} vrrp_instance VI_1 {state MASTER # BACKUP interface eth0 # B 'g virtual_Router_id 51 priority 100 # Set different priorities for the active and standby hosts. Advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipAddress {192.168.200.16 # Configure virtual server}}Copy the code

Add the detection script to /usr/local/src

#! /bin/bashA=`ps -C nginx - no-header |wc -l` if [ $A -eq 0 ]; then /usx/local/nginx/sbin/nginx sleep 2 if [ `ps -C nginx --no-header |wc -l` -eq 0 ]; then killall keepalived fi fiCopy the code

Nginx principle Master worker Worker number of CPU cores recommended, such as 8 cores 8

nginx.conf
worker_processes  1; 
Copy the code

Nginx and Redis IO multiplexing mechanisms