Installation and configuration under Nginx windows

1: Download File: http://nginx.org/en/download.html select the operating system, select the version, and now use the latest version for demonstration; 2: 1. After the download is completed, decompress, run cmd, use the command to operate, do not double-click nginx.exe directly, do not double-click nginx.exe directly, do not double-click nginx.exe directly, do not double-click nginx.exe directly in the dos window to start, do not double-click nginx.exe directly, which will lead to invalid restart and stop nginx after modifying the configuration, and you need to manually close all N in the task manager Ginx process. Restart it. 2. Use the command to reach the compressed directory of nginx

cd c:\nginx-1.15.2

3. Start nginx service, it is normal that it will flash by when starting

start nginx

4. Check whether the task process exists, dos or open the task manager

tasklist /fi "imagename eq nginx.exe"

If there is no startup error, check the log. error.log is a common error in log file under logs folder in nginx Directory:

(1) Port number occupied

(2)nginx folder path including Chinese

For other errors, see the description in the log in detail. 5. Save after modification. Use the following command to check whether the configuration file is correct, followed by the path of nginx.conf file. successful means it is correct

nginx -t -c /nginx-1.15.2/conf/nginx.conf

6. If the program is not started, start nginx directly. If it is already started, reload the configuration file and restart it with the following command.

If the program is not started, start nginx directly. If it is already started, reload the configuration file and restart it with the following command

7: Open the browser to access the domain name and port http://localhost:8800, and the welcome page will show that the deployment is successful. 3. Configuration optimization. Open nginx.conf to configure according to your own needs. Here are some simple general tuning configurations

worker_processes  1;
events {
    worker_connections  1024;
}

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

    sendfile        on;

    keepalive_timeout  65;

    server_names_hash_bucket_size 512;

    server {
        
        listen       8800;
        
        server_name  localhost;
        
        charset utf-8;

        location / {
            
            root   html;
            
            index  index.html index.htm;
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-	 	Modified-Since,Cache-Control,Content-Type';

            proxy_set_header Host $host;
            
            proxy_set_header X-Real-IP $remote_addr;
            
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            
            proxy_set_header Cookie $http_cookie;
            
            proxy_redirect off;
    
            proxy_cookie_domain localhost .testcaigou800.com;

            proxy_connect_timeout 30;
        }

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

    }
    
  server {
    listen 80;
    server_name www.abc.com;
    charset utf-8;
    location / {
      proxy_pass http://localhost:10001;
    }
  }
  server {
    listen 80;
    server_name aaa.abc.com;
    charset utf-8;
    location / {
      proxy_pass http://localhost:20002;
    }
  }
}
Published 18 original articles, won praise 2, visited 10000+
Private letter follow

Tags: Nginx

Posted on Tue, 14 Jan 2020 21:42:04 -0800 by remmargorp