Nginx explain the installation, operation, and configuration files in windows

First, install Nginx (windows version)

    1, into the Nginx official website to download the installation package;

    Nginx official website Download

Nginx official website to download the installation package

    2, decompressing the downloaded compressed, and remember extraction path;

    3, open the console (cmd), into the installation package Nginx root path;

    4, enter the command nginx nginx -t check whether the configuration is successful;

    5, enter the command start nginx nginx start the service;

Start Nginx Service

    6, access localhost in your browser, you can see the page nginx successfully installed and running. (The default listening port 80)

Two, Nginx commonly used commands

    1, check whether the profile configuration, run before you start the service;

nginx -t

    2, start running nginx services;

start nginx

    3, after the task is completed, etc., close Nginx services;

nginx -s quit

    4, Nginx forced to shut down service;

nginx -s stop

    5. After the restart Nginx service, usually modified the configuration file, the changes to take effect;

nginx -s reload

Third, explain profile

    Nginx nginx.conf all settings are at the root of the file in the conf folder.

    Seen on the Internet, not to Notepad to open the conf configuration file , transcoding problem occurs, destroy the contents of the configuration file, resulting in Nginx does not start up. I use Notepad ++ to open the modification, no problem.

    1, worker_processes: set the number of working processes when Nginx, a number smaller than the number of cores cpu;

worker_processes  1;

     2、events:

events {
    # 设置nginx的最大连接数
    worker_connections  1024;
}

    3, keepalive_timeout: http connection timeout, default is 65s. To upload large files, need to be properly set larger to avoid the file upload process is disconnected, leading to the failed files;

keepalive_timeout  5000; 

    4, gzip: data compressing the content for network transmission;

gzip  on;

    5, upstream: the cluster server. We can set a number of different names of clusters for different server. Here you can set nginx work strategy here is to use the default polling;

# 服务器的集群  
upstream  localhost {  #服务器集群名字
    server    192.168.100.31:8801;
    server    192.168.100.32:8802;
    server    192.168.100.33:8803 down;
    server    192.168.100.34:8804 backup;
}  

   Note: Each of the upstream server can set the following states:

  • weight- service sets the access weight, the greater the weight the greater the chance of being accessed, the greater the corresponding pressure;
  • down- indicates that the server does not participate in load;
  • max_fails - allows the maximum number of failed requests; returned when an error exceeding a defined proxy_next_upstream;
  • fail_timeout: time to pause after access request fails;
  • backup: Alternate Server; all busy or if other machines when down, will be used.

    6, server: proxy server, you can set up multiple proxy servers (each server is a virtual server); request comes after the decision by the server_name server of the request which service access;

server {
    # 设置监听端口
    listen      9876;
    server_name  localhost;
    
    # 设置url编码格式,解决参数中文乱码问题
    charset utf-8;
		
    location / {
        proxy_pass http://localhost;  
        proxy_redirect default;  
    } 

    7, location: Configure access rules for that service under one server can configure multiple location;

# 对静态资源进行映射
location ^~ /public/images/ {  
    alias D:/nginx-1.10.1/html/public/images/;
}

# 对"/"启用负载均衡
location / {
    proxy_pass http://localhost/;
    proxy_redirect default;
}
  • root- real path to the resource assignment request on the server, can write a relative path (relative to the install directory nginx) can also be written absolute path;
  • alias- specify the actual path of the resource on the server requests, can write a relative path (relative to the install directory nginx) can also be written absolute path;
  • index- designated access the home page will find in the root directory of the set may be followed by more than one page, then click Find Now to find a return that is;
  • proxy_pass- set up a forwarding address access;

Note: the difference between using the alias of root

    1, the resource access path for the root  root access address + location specified address , the resource access path for the alias  alias specified path ;

# 用户访问地址:http://location/images/login.jpg

# root模式下
location /images/ {
  root E:/public;
}
# 访问的资源路径为: E:/public/images/login.jpg

# alias模式下
location /images/ {
  alias E:/public/;
}
# 访问的资源路径为: E:/public/login.jpg

    2, alias only for location but root can be used in server, http and location in;

    3, alias path must be specified after the "/" at the end, it is a folder, but the root can not end with "/."

   Nginx configuration about the location, I have another blog post in detail, are interested can look welcome wrong finger. Attach Bowen Address: Nginx configuration methods in location, and matching rules

 

Published 47 original articles · won praise 16 · views 70000 +

Guess you like

Origin blog.csdn.net/zorro_jin/article/details/84927408