Installation and configuration Nginx windows

One: Download file: http://nginx.org/en/download.html select the operating system, select the version, and now with the latest version of the presentation; two: Install 1, after the download is complete, unzip, run cmd, use the command operation Do not double-click nginx.exe, do not double-click nginx.exe, do not have to start in dos window by double-clicking directly nginx.exe, do not double-click nginx.exe, this will lead to change the configuration after the restart, stop nginx invalid, need to manually shut down All nginx processes in task Manager, and then we can start. 2, use the command to reach the directory nginx increase after compression

cd c:\nginx-1.15.2

3, start nginx service, will flash when you start it off is normal

start nginx

4, view the task process exists, dos or open the Task Manager will do

tasklist /fi "imagename eq nginx.exe"

If you are not likely to start being given a look at the log, logs files in the directory folder nginx is the log file error.log common errors:

(1) port number is occupied

(2) nginx folder path with Chinese

Other errors see detailed description 5 log in to save the changes are complete, check the configuration file is correct using the following command, followed by the file path nginx.conf, successful shows correctly

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

6, if the program did not start directly start nginx start, if you have started to use the following command to reload the configuration file and restart.

如果程序没启动就直接start nginx启动,如果已经启动了就使用以下命令重新加载配置文件并重启

7: Open a browser to access just the domain name and port http: // localhost: 8800, the Welcome page it shows the success of the deployment of the three configuration optimization. Open nginx.conf be configured according to their needs, a simple list of some of the conventional tuning below configuration

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 21 original articles · won praise 2 · views 10000 +

Guess you like

Origin blog.csdn.net/pengxiaojia9516/article/details/103986694