The configuration and configuration file section of Windows for Nginx

  • 2020-05-12 07:00:29
  • OfStack

1. In the official website to download nginx Windows version of's official website to download: http: / / nginx org/download /

Select the version you want to download and unpack nginx (for example, nginx-1.6.3) to the directory on your window drive.

Do the following :(keep in mind that you will use it often)

nginx -s stop // stop nginx
nginx-s reload // reload the configuration file
nginx-s quit // quit nginx

2. The next step is to configure the nginx conf file. What nginx needs to configure is in the conf file. Now let's introduce the configuration of conf file:


#user nobody;
worker_processes 2;  # Number of processes, initially set to cpu The total number of nuclear 
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid; # Used to manage nginx process 
events {
worker_connections 1024; # A single worker The maximum number of connections a process can make 
}
http {  
include mime.types; # File extension and file type mapping table 
default_type application/octet-stream; # Default file type 
#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;  # Enable efficient file transfer mode, kernel zero copy 
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65; # Connection timeout in seconds 
#gzip on;
server {
listen 8089; # The port number of the connection 
server_name localhost;
autoindex on;
#charset koi8-r;
#access_log logs/host.access.log main;
# The following is the format requirement for you to receive the transferred file. According to your needs, I will use it to receive the image ( jpg... ) 
location ~ .*\.(gif|jpg|jpeg|png|bmp)$ { 
expires 24h; # The client caches the above static data 
root C:/resources/images/; # The file path 
access_log C:/nginx-1.6.3/logs/log_test.log;
proxy_store on; 
proxy_store_access user:rw group:rw all:rw; 
proxy_temp_path C:/resources/images/;# The file path 
proxy_redirect off; 
#autoindex on;
proxy_set_header Host 127.0.0.1; # Fill in your ip
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
client_max_body_size 10m; 
client_body_buffer_size 1280k; 
proxy_connect_timeout 900; 
proxy_send_timeout 900; 
proxy_read_timeout 900; 
proxy_buffer_size 400k; 
proxy_buffers 40 320k; 
proxy_busy_buffers_size 640k; 
proxy_temp_file_write_size 640k; 
if ( !-e $request_filename) 
{ 
proxy_pass http://127.0.0.1:8089; 
} 
}
# So here's what I did with the transmission mp3 Format configuration 
location ~* .(mp3)$ {
expires 24h; 
root C:/resources/voice/; # The file path 
proxy_store on; 
proxy_store_access user:rw group:rw all:rw; 
proxy_temp_path C:/resources/voice/;# The file path 
proxy_redirect off; 
proxy_set_header Host 127.0.0.1; 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
client_max_body_size 10m; 
client_body_buffer_size 1280k; 
proxy_connect_timeout 900; 
proxy_send_timeout 900; 
proxy_read_timeout 900; 
proxy_buffer_size 40k; 
proxy_buffers 40 320k; 
proxy_busy_buffers_size 640k; 
proxy_temp_file_write_size 640k; 
if ( !-e $request_filename) 
{ 
proxy_pass http://127.0.0.1:8089 ; 
} 
}
location / {
root html;
index index.html index.htm;
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# Here is the configuration https
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}

3. Precautions

Problems encountered:

1. After configuring conf, you cannot start nginx, which means there is something wrong with your conf file configuration. You need to go back and check. {} missing, file path name wrong, etc.

2. Sometimes the entire http and https configuration files will be used as needed. You only need to configure the http {} and https{} contents.


Related articles: