“This is the 19th day of my participation in the Gwen Challenge.

Nginx: Nginx: Nginx: Nginx: Nginx

Virtual host

Virtual host is a special software and hardware technology, it can be divided into a network of each computer into multiple virtual hosts, each virtual host can independently provide WWW services, so you can achieve a host to provide multiple web services, between each virtual host is independent, each other.

Virtual host configuration can be realized through Nginx. Nginx supports three types of virtual host configuration.

http{
	server{
		# represents a virtual host}}Copy the code

Ip-based virtual hosting

One host can be bound to multiple IP addresses, that is, one NIC can be bound to multiple IP addresses.

Domain-based virtual hosting

Configuring local Hosts

192.168.85.200 moe.com
192.168.85.200 zoe.com
Copy the code

Configure nginx

Configure two directories

[root@localhost /]# ll -R mzoe/
mzoe/:
total 0
drwxr-xr-x. 2 root root 24 Jun  4 01:16 moe.com
drwxr-xr-x. 2 root root 24 Jun  4 01:16 zoe.com

mzoe/moe.com:
total 4
-rw-r--r--. 1 root root 20 Jun  4 01:16 index.html

mzoe/zoe.com:
total 4
-rw-r--r--. 1 root root 23 Jun  4 01:16 index.html
Copy the code

Configure two servers

server { listen 80; server_name moe.com; location / { root /mzoe/moe.com/; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 80; server_name zoe.com; location / { root /mzoe/zoe.com/; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }}Copy the code

Port-based virtual host

Different ports for the same IP address

server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 88; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }}Copy the code

Reload configuration and troubleshoot errors

Reload configuration

systemctl reload nginx.service
Copy the code

Viewing Error Details

systemctl status nginx.service -l
Copy the code

The reverse proxy

proxy_pass

Note the slash at the end of proxy_pass, no access!!

server { listen 80; server_name mrc.com; location /mrc { proxy_pass http://www.baidu.com/; }}Copy the code

Load balancing based on reverse proxy

    upstream mrc {
      server 192.168.85.200:88;
      server 192.168.85.200:99;
    }

    server {
        listen       80;
        server_name  mrc.com;

        location / {
            proxy_passhttp://mrc/; }}server {
        listen       88;
        server_name  moe.com;

        location / {
            root   /mzoe/moe.com/;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            roothtml; }}server {
        listen       99;
        server_name  zoe.com;

        location / {
            root   /mzoe/zoe.com/;
            index  index.html index.htm;
        }

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

Weight (weight)

Specifies the polling probability, weight proportional to the access ratio, for cases where back-end server performance is uneven.


    upstream mrc {
      server 192.168.85.200:88 weight=10 down;
      server 192.168.85.200:99 weight=1;
      server 192.168.85.200:100 weight=10 backup;
    }

Copy the code
  • Down: indicates that the current server does not participate in the load
  • Weight: The default value is 1. The greater the weight, the greater the weight of the load.
  • Backup: Request the backup machine when all other non-backup machines are down or busy.

Domain name, DNS, SSL

Domain name to apply for

Domain name application has multiple channels, here is ali Cloud application domain name.

Aliyun domain name application address

Domain console

Then enter the domain name console, apply for further authentication information, must be authenticated after the domain name can pass.

Domain name resolution

After applying for domain names, configure domain name resolution and add the mapping rule between domain names and IP addresses.

SSL Certificate Application

Here I apply for Tencent Cloud TrustAsia SSL certificate – Domain name free version (DV), of course, Ali Cloud also has related SSL certificate application. You can apply by yourself.

Aliyun SSL certificate link address

Tencent cloud SSL certificate link address

The SSL certificate is bound to the domain name

conclusion

This article describes how Nginx can be used for reverse proxy, load balancing, virtual host configuration, and then describes the domain name application, DNS configuration, public network configuration HTTPS SSL certificate configuration. The next article describes installing SSL certificates on Nginx servers.

Welcome everyone to pay attention to the public account (MarkZoe) to learn from each other and communicate with each other.