Just a joke

Seldom contact nginx, only a vague understanding, know is can reverse proxy, the effect of load balance, in the company as long as to ops, or get help operations staff configuration, with respect to ok, I also smoke for a long time at the nginx’s website and API documentation, that’s every word, don’t even know it is ~, Give up now feel that the front end as long as it will be simple to configure the proxy

background

Go to the nginx installation directory \conf\nginx.conf and open it

The code shown


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    underscores_in_headers on;
    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
	
	server {
	    listen       5000; Server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; Root D:\\object\\yuezhu\\vueHuka\ dist\\; index index.html index.htm; } location /hukaApp2/ {#alias is a directory alias definition configuration item path (jump) alias D:\object\yuezhu; index index.html index.htm; } location/API / {#proxy_pass:/ / 192.168.1.123:8082 /;
	    }
		  location /business/ {
	        proxy_pass http:/ / 192.168.1.123:8085 /;
	    }
		
	    location /daike/ {
	        proxy_pass http:/ / 192.168.1.123:8088 /;
	    }
	    location /pay/ {
	        proxy_pass http:/ / 192.168.1.123:8086 /;
	    }
	    location /login/ {
	        proxy_pass http:/ / 192.168.1.123:8083 /;
	    }
	
	    #error_page  404              /404.html;
	
	    # redirect server error pages to the static page /50x.html
	    #
	    error_page   500 502 503 504  /50x.html;
	    location = /50x.html {
	        root   html;
	    }
	}


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

Copy the code

Code Description (Mainly for Serve)

  1. Serve {} // A serve represents a service, such as a local project’s NPM run dev startup environment
  2. # represents the comment equivalent of js //
  3. Listen // The current port number
  4. Server_name // Why is the current name IP or domain name
  5. Location // According to the URI to carry out different positioning, is essential in the virtual host, location can locate different parts of the site, positioning to different processing methods

Location code block detailed insight

  1. Syntax matching rules (clicking on regular rules is actually easier to understand and use)
The title meaning
location = /uri = indicates an exact match. It takes effect only when the match is complete
location ^~ /uri Prefix matches the URL path beginning with ^~, and precedes the re.
location ~ pattern The beginning of ~ indicates case-sensitive regular matching
location ~* pattern The beginning indicates case-insensitive regular matching
location /uri Without any modifiers, it also indicates a prefix match, but after the re match
location / Generic matching, any request that does not match another location will be matched, equivalent to the default in the switch
  1. Root Configuration item Path Root is the definition of the uppermost directory

  2. Alias Alias is the definition of a directory alias. Configure the item path (such as a jump)

  3. Proxy_pass proxy forwarding

  4. index index.html index.htm; The default home page