[Windows installation] Windows detailed installation nginx deployment tutorial

1. Download first and go directly to the official website nginx.org

 After clicking, it will be downloaded. After the download is complete, the installation will start. In fact, the official website has already told how to install it. There are detailed instructions in "documentation -> nginx windows" on the right, only in English

2. After the download is complete, unzip, run cmd, and use commands to operate. Do not double-click nginx.exe directly
. , this will cause restarting and stopping nginx to be invalid after modifying the configuration. It is necessary to manually close all nginx processes in the task manager and restart them.
 

3. Use the command to reach the compressed directory of nginx

cd c:\nginx-1.15.2

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

start nginx

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

tasklist /fi "imagename eq nginx.exe"

 

 Open the task manager and you cannot see the nginx.exe process in the process (it will be displayed here when you double-click nginx.exe), you need to open the detailed information to see the hidden nginx.exe process

 If there is none, it may be that the startup has reported an error. Check the log. The error.log is the log file under the logs folder in the nginx directory.

 

 

Common mistakes:

(1) The port number is occupied

(2) The nginx folder path contains Chinese

For other errors, see the description in the log in detail

 6. Modify the configuration file, enter the decompression directory, and click on the folder directly, no need to operate from dos

 Find nginx.conf in the conf directory and use the txt text to open it. Find the server node and modify the port number. If you need to modify the home page directory, you don’t need to modify it.

 Save after the modification is complete, use the following command to check whether the configuration file is correct, followed by the path of the nginx.conf file, successful means it is correct

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

 

 If the program is not started, start nginx directly. If it has been started, use the following command to reload the configuration file and restart

nginx -s reload 

After that, open the browser to access the domain name and port http://localhost:8800 just now, and the welcome page will appear, indicating that the deployment is successful 

 

7. Close the nginx service and use the following command. It is also normal to see if the process has disappeared. 

quick stop

nginx -s stop

complete and orderly shutdown

nginx -s quit

 8、

Optimization

Open nginx.conf and configure according to your own needs. Some simple general tuning configurations are listed below

 #user nobody;
 
#==The number of working processes, generally set to the number of cpu cores
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 {     #==Maximum number of connections, generally set to cpu*2048     worker_connections 1024; } http {     include mime.types;     default_type application/octet-stream;     #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;
    
    #==client link timeout
    keepalive_timeout 65;
 
    #gzip on;
 
    #When configuring multiple server nodes, the default server names buffer size is not enough, you need to manually set the size A little
    server_names_hash_bucket_size 512;
 
    #server indicates that the virtual host can be understood as a site, and multiple server nodes can be configured to build multiple sites #Each
    request comes in to determine which server to use is determined by server_name server
    {         #Site listening port         listen 8800;         #Site access domain name         server_name localhost;         #Encoding format, to avoid garbled url parameters         charset utf-8;         #access_log logs/host.access.log main;         #location is used to match multiple URI access rules under the same domain name         #For example, how to jump to dynamic resources, static How do resources jump, etc.




        


 

 


        The / followed by #location represents the matching rule
        location / {             #Site root directory, which can be a relative path or an absolute path             root html;             #Default homepage             index index.html index.htm;             #Forwarding backend site address, generally used For soft load, poll the backend server             #proxy_pass http://10.11.12.237:8080;             #Reject the request, return 403, generally used for certain directories to prohibit access             #deny all;             #Allow request             #allow all;             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'; #Redefine
            or Add the request header sent to the backend server
            #Add the client request host name to the request header
            proxy_set_header Host $host;
            #Add the client IP to the request header
            proxy_set_header X-Real-IP $remote_addr;
            #Add the $remote_addr variable value to After the client "X-Forwarded-For" request header, separated by commas. If the client request does not carry the "X-Forwarded-For" request header, the $proxy_add_x_forwarded_for variable value will be the same as the $remote_addr variable  
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #Add the client's Cookie to the request
            header proxy_set_header Cookie $http_cookie;
            # Will be replaced with the primary domain name and port number of the proxy server. If the port is 80, it can be omitted.
            proxy_redirect off;
            
            #Browsers have many restrictions on cookies, if the Domain part of the cookie does not match the Domain of the current page, it cannot be written.
            #So if A domain name is requested, the server proxy_pass to B domain name, and then B server outputs Domian=B cookie,
            #The front-end page still stays on A domain name, so the browser cannot write the cookie.
            
           #Not only the domain name, but the browser also has restrictions on Path. We often proxy_pass to a Path of the target server,
            #Do not expose this Path to the browser. At this time, if the cookie of the target server is hard-written, the problem that the cookie cannot be written will also occur.
            
            #Set the replacement text of the domain attribute in the "Set-Cookie" response header, its value can be a string, a regular expression pattern, or a quoted variable #If the forwarding backend server needs a cookie, it needs to set the cookie domain as
            well Conversion, otherwise the front-end domain name and the back-end domain name are inconsistent and the cookie will not be accessible
        #Configuration rules: proxy_cookie_domain serverDomain (back-end server domain) nginxDomain (nginx server domain)
            proxy_cookie_domain localhost .testcaigou800.com;
            
            #Cancel all proxy_cookie_domain directives at the current configuration level
            #proxy_cookie_domain off;
            #The timeout period for establishing a connection with the backend server. Generally, it is impossible to exceed 75 seconds;
            proxy_connect_timeout 30;
        }
 
        #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;         }     }   #When you need to listen to multiple domain names on the same port, use the following configuration. The same port has different domain names, and the server_name can also be configured using regular expressions. #But pay attention to the fact that there are too many servers and you need to manually expand the   server_names_hash_bucket_size buffer size   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;
    }
  }
}

Guess you like

Origin blog.csdn.net/wufaqidong1/article/details/131072120