Nginx configuration and configuration file section in Windows, nginx configuration file

Source: Internet
Author: User

Nginx configuration and configuration file section in Windows, nginx configuration file

One, download nginx Windows version on the official website, the official website download: http://nginx.org/download/

Select the version you want to download and decompress the nginx (such as nginx-1.6.3) package to the directory in your window disk.

Perform the following operations: (remember that this operation is frequently used)

Nginx-s stop // stop nginx

Nginx-s reload // reload the configuration file
Nginx-s quit // exit nginx

 

2. Configure the nginx conf file. The configuration required for nginx is in the conf file. Now we will introduce the configuration of the conf file:

 


# User nobody;
Worker_processes 2; # Number of processes, which can be set to the total number of cpu cores initially

 

# 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 Processes

 


Events {
Worker_connections 1024; # maximum number of connections of a single worker process
}

 


Http {
Include mime. types; # file extension and file type ing 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 the efficient file transfer mode to achieve zero copy of the kernel
# Tcp_nopush on;

 

# Keepalive_timeout 0;
Keepalive_timeout 65; # connection timeout, in seconds

# Gzip on;

 

Server {
Listen 8089; # connected port number
Server_name localhost;
Autoindex on;
# Charset koi8-r;

 

# Access_log logs/host. access. log main;

# The following is the format requirement for receiving the transmitted file. You can use it as needed. I will use it to receive the image (jpg ...)
Location ~ . * \. (Gif | jpg | jpeg | png | bmp) $ {

Expires 24 h; # The client caches the above static data
Root C:/resources/images/; # 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/; # file path
Proxy_redirect off;

# Autoindex on;
Proxy_set_header Host 127.0.0.1; # Enter your ip address
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Client_max_body_size 10 m;
Client_body_buffer_size 1280 k;
Proxy_connect_timeout 900;
Proxy_send_timeouts 900;
Proxy_read_timeout 900;
Proxy_buffer_size 400 k;
Proxy_buffers 40 320 k;
Proxy_busy_buffers_size 640 k;
Proxy_temp_file_write_size 640 k;
If (! -E $ request_filename)
{
Proxy_pass http: // 127.0.0.1: 8089;
}
}

# The following is the configuration of the mp3 format used for transmission.
Location ~ *. (Mp3) $ {

Expires 24 h;
Root C:/resources/voice/; # file path
Proxy_store on;
Proxy_store_access user: rw group: rw all: rw;
Proxy_temp_path C:/resources/voice/; # 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 10 m;
Client_body_buffer_size 1280 k;
Proxy_connect_timeout 900;
Proxy_send_timeouts 900;
Proxy_read_timeout 900;
Proxy_buffer_size 40 k;
Proxy_buffers 40 320 k;
Proxy_busy_buffers_size 640 k;
Proxy_temp_file_write_size 640 k;
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 x.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 Fig: 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;
#}
#}

 

# Configure https
# HTTPS server
#
# Server {
# Listen 443 ssl;
# Server_name localhost;

 

# Ssl_certificate cert. pem;
# Ssl_certificate_key cert. key;

 

# Ssl_session_cache shared: SSL: 1 m;
# Ssl_session_timeout 5 m;

 

# Ssl_ciphers HIGH :! ANULL :! MD5;
# Ssl_prefer_server_ciphers on;

 

# Location /{
# Root html;
# Index index.html index.htm;
#}
#}

}

3. Notes

Problems:

1. After configuring the conf file, you cannot start nginx. This indicates that the configuration of your conf file is incorrect. You need to go back and check it. For example, {} is missing, and the file path is incorrect.

2. Sometimes the entire configuration file of http and https is used as needed. You only need to configure the content in http {} And https.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.