What is load balancing? When a domain name points to multiple web servers, add an nginx load balancing server. Through nginx load balancing, requests from clients can be sent to each web server in a balanced manner, avoiding the imbalance of a single server being overloaded while the other servers are relatively idle. Configure nginx load balancing: Create a new configuration file on the nginx machine: [root@centos02 ~]# vi /etc/nginx/conf.d/test.conf Add the following content: upstream test { ip_hash; server 192.168.0.10:80 weight=100; server 192.168.0.20:80 weight=50; } server { listen 80; server_name www.test.com; location / { proxy_pass http://test; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
Verify the nginx configuration and reload: [root@centos02 ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@centos02 ~]# nginx -s reload Next, modify the client hosts file to point the test domain name www.test.com to the IP of the tested nginx load balancing machine to access the www.test.com website. Load balancing configuration example supplement 1. According to the requested file configuration: upstream aa { server 192.168.0.10; server 192.168.0.20; } upstream bb { server 192.168.0.100; server 192.168.0.101; } server { listen 80; server_name www.test.com; location ~ aa.php { proxy_pass http://aa/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~ bb.php { proxy_pass http://bb/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location / { proxy_pass http://bb/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } Requests to aa.php will go to group aa, requests to bb.php will go to group bb, and all other requests will go to group bb. You must have location / {}, otherwise the URL cannot be matched correctly. 2. Configure according to the requested directory: upstream aa { server 192.168.0.10; server 192.168.0.20; } upstream bb { server 192.168.0.100; server 192.168.0.101; } server { listen 80; server_name www.test.com; location /dir1/ { proxy_pass http://aa/dir1/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /dir2/ { proxy_pass http://bb/dir2/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location / { proxy_pass http://bb/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } #When the request uri matches /dir1/, proxy to aa/dir1/, match /dir2/ or others, proxy to bb/dir2/ Nginx configures SSL certificate to access the website through https protocol: SSL certificate application website: 1. https://www.wosign.com/ #After generating through the browser, you need to create a certificate file on the server Create the certificate files: [root@linux ~]# mkdir /etc/nginx/ssl [root@linux ~]# cd !$ cd /etc/nginx/ssl [root@linux ssl]# touch ca [root@linux ssl]# touch test.crt [root@linux ssl]# touch test.key #Add the content of the corresponding certificate provided by the certificate application website to the ca/.crt/.key file Edit the nginx configuration file: [root@linux ~]# vi /etc/nginx/conf.d/bbs.conf Add the following content: listen 443 ssl; server_name test.bbs.com; ssl on; ssl_certificate /etc/nginx/ssl/test.crt; #define .crt file path ssl_certificate_key /etc/nginx/ssl/test.key; #define .key file path ssl_protocols TLSv1 TLSv1.1 TLSv1.2; Verify the configuration and reload nginx: [root@linux ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@linux ~]# nginx -s reload #Next, visit the website address bar to display HTTPS Curl verification method: curl -k -H "host:test.bbs.com" https://192.168.234.128/index.php #host: domain name, https:// webserver IP, the output result is the website page tag information, which means success The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: The difference between MySQL database stored procedures and transactions
>>: Summary of the understanding of virtual DOM in Vue
1. Use CSS Copy code The code is as follows: style...
The basics of MySQL knowledge points for the seco...
Table of contents 1. Home Page Production 1. Prod...
The establishment of MySQL index is very importan...
Enable remote access Enable remote access rights ...
Occasionally you'll see characters such as ...
WeChat applet form validation, for your reference...
PCIE has four different specifications. Let’s tak...
Preface You may often receive warning emails from...
Preface Since the most important data structure i...
Insert data into mysql database. Previously commo...
Quoting Baidu's explanation of pseudo-static:...
<br />This example mainly studies two parame...
Understanding object.defineProperty to achieve re...
In the process of making web pages, it is inevita...