nginx reverse proxy configuration to achieve multi-domain and multi-terminal slogan

Deployment of multiple services on the same server, use a different port.

 

First, the thought process

  1. If you do not want to bring the port number, you can only access port 80 or 443.
  2. It can be used to distinguish secondary directory service, through a reverse proxy forwarded to a different Server.
  3. Subdomain can be used to distinguish between services, through the reverse proxy forwarded to a different Server.

Second, program evaluation

  1. Without access to the port number to my current experience, the other can not find a better way, can only use 80 or 443 ports.
  2. Use secondary directory distinguished service, great feasibility.
    • Through the secondary directory name, a clear distinction between services.
    • But direct and port number is not very different, but the method to distinguish the service from the port number into a secondary directory names.
    • It may cause url too long.
    • Still no aesthetics.
  3. Subdomain differentiated services, feasibility and secondary directory is almost the same.
    • By subdomain, a clear distinction between services.
    • It has a certain appearance.

Third, the practical operation

Subdomain way to distinguish the service, and then use nginx reverse proxy to do, distributed to a different port.

1, nginx configuration files found

  Nginx open profile, the open / installation path /conf/nginx.conf, configure

2, modify the configuration

{Server 

        the listen 80; 

        server_name * .abc.com; 

        IF {# regex (HTTP_HOST $ ~ * "^ (*) \ ABC \ $ .com.?.") 

                SET $ $ Domain. 1; Set # variable 
        } 


        LOCATION / { 

            IF ($ ~ * domain "Shop") { 

               proxy_pass http://abc.com:3001; # domain has shop, forwarded to port 3001 

            } 

            IF ($ ~ * domain "mail") { 

               proxy_pass HTTP: // abc.com:3002; # domain has mail, forwarded to port 3002 

            } 


            TCP_NODELAY ON; 

            proxy_set_header $ Host Host; 

            proxy_set_header the X-Real-IP-$ REMOTE_ADDR;

            the X-Forwarded-the For-proxy_set_header $ proxy_add_x_forwarded_for; 

            # above three lines aimed at the user's proxy server receives information transmitted on a real server 


            root HTML; 

            index index.html index.htm; # default 

        } 

}

  

 

 

 

 

 

 

Build personal blog wordpress + docker

Guess you like

Origin www.cnblogs.com/panchanggui/p/12064427.html