Nginx deployment notes windows (1)

Time:2020-10-18

aboutFront and rear separationDue toIf the ports of the pages and services are inconsistent, cross domain problems will occurTherefore, reverse proxy must be used to solve cross domain problems.

1、 Get nginx

Nginx deployment notes windows (1)

You can get it from the official website. Select a version in the above figure and unzip it directly after downloading.

takeUnzip the entire folder, copy to the target computer / server. (here we usenginx-1.14.2For example)

⚠️Note: nginx does not need to be installed. It can be used out of the box

Nginx deployment notes windows (1)

As shown in the figure above, this is a typical onenginxFile directory structure.

  • Configuration file:nginx-1.14.2/conf/nginx.conf
  • Front end code:nginx-1.14.2/project
  • Error message (default)nginx-1.14.2/logs/error.log

2、 Configure nginx

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    # tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;

    Upstream web1 {# load balancing module
        server  localhost:8080;  #Service address
    }

    server {
        Listen 8000; listen port
        server_ Name localhost; ා front end address
        Root project; # front end project file directory

        Location / {routing module
            index index.html index.htm;
            Auto index on
            #autoindex_exact_size off;
            #autoindex_localtime on;
        }

        Location ^ ~ / API / {service request broker
            proxy_pass http://web1;
            proxy_set_header X-real-ip $remote_addr;
            proxy_set_header Host $http_host;
        }

        error_page  500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
  }

The above is onetypicalsimpleFor example, the front-end project is deployed in thehttp://localhost:8000IfRequest addresshave/api/Is treated as a request service and will be proxied tohttp://localhost:8080

Next, start nginxstart nginx

3、 Nginx common commands

  • Start service:start nginx
  • Forced stop:nginx -s stop
  • Forced restart:nginx -s reload
  • Forced exit:nginx -s quit
  • Test configuration:nginx -t
  • Forced closurewindowslowerAll nginx processestaskkill /im nginx.exe /f

A kind of Note: aboveCommand starting with nginxbycmdUsing the command in the,powershelIf you want to use it in PowerShell, you need tonginxReplace with.\nginxFor examplenginx -s reload->.\nginx -s reload

Nginx deployment notes windows (1)

4、 Nginx common errors

1. Use administrator permission to open CMD

Nginx deployment notes windows (1)

2. Nginx – s reload needs to be used after start nginx

Nginx deployment notes windows (1)