Installation and simple configuration of nginx in Windows environment

Source: Internet
Author: User
Tags sendfile

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

I. Download and install Nginx

Go to nginx website to download

I choose nginx/windows-1.10.3 version here, download and extract it, the extracted path can not contain Chinese

After I unzip it, place the path as follows

Second, start running

Under current directory, press and hold shift+ right mouse button, select "Open Command Window Here", then enter start Nginx

At this point, you can enter the browser input access address, HTTP://127.0.0.1/or http://localhost/to access

Three, the configuration file explanation

The core configuration file is nginx.conf, which is located in the Conf directory, and in most cases we modify the configuration of the file.

The original configuration of the file is as follows:

#user nobody;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 {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;    Keepalive_timeout 65;    #gzip on;        server {Listen 80;        server_name localhost;        #charset Koi8-r;        #access_log Logs/host.access.log Main;            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 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$ {# ProX        Y_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 # #l        ocation ~/\.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;    #} #} # 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; #    }    #}}

  

Where # Represents a comment

Nginx Our main role is to do reverse proxy and load balancing, which I will focus on later on. It is also a Web server that can be used to host Web services, as we commonly use for Apache, Tomcat, and IIS.

This chapter introduces a few important parameters of the configuration file, followed by the Nginx deployment of PHP and Python project again to focus on, the Java project is usually tomcat+nginx at the same time to configure, Nginx used to do load balancing and processing static pages.

1, define the user and user group Nginx run

#user  Nobody;

2, Nginx process number, recommended to set equal to the total number of CPU cores

Worker_processes 1;

3. Global error log definition type, [Debug | info | notice | warn | error | crit]

#error_log logs/error.log notice; #error_log logs/error.log info;

4. Process files

#pid        Logs/nginx.pid;

5, the working mode and the maximum number of connections: Worker_connections is the largest number of concurrent links for a single background worker process, and the total number of concurrent worker_processes and Worker_connections is the product of Max_ Clients = worker_processes * worker_connections

Events {worker_connections 1024;}

6. Some configuration under HTTP and its significance

Include Mime.types; #文件扩展名与文件类型映射表default_type Application/octet-stream; #默认文件类型sendfile on; #开启高效文件传输模式, the sendfile instruction specifies whether Nginx calls the Sendfile function to output the file, and for normal applications to be set to ON, if it is used for downloading applications such as disk IO heavy load applications, can be off to balance disk and network I/O processing speed, Reduce the load on the system. Note: If the picture does not appear normal, change this to off. AutoIndex on; #开启目录列表访问, the appropriate download server, the default shutdown. Tcp_nopush on; #防止网络阻塞tcp_nodelay on; #防止网络阻塞keepalive_timeout 120; #长连接超时时间, the unit is in seconds gzip on; #开启gzip压缩输出

7, the server virtual host related configuration

We usually configure a variety of servers, the most configuration is these places

Like what:

http{#虚拟主机1 server{  listen       ;   #监听端口, changes are made here, such as 192.168.1.100:8080, based on the IP configuration;  server_name  www.xdw.com;  #主机域名, the actual project release, fill the public domain name, local deployment, you can add IP and domain names in the C:\Windows\System32\drivers\etc\hosts file map location  /{#映射解析,/representing the root path , there are analytic methods of regular expressions here, please refer to Http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_core_module.html#location     Root   e:/xdw/0221;   #工程所在路径     index  index.html index.htm;  #首页 (Default page)  }} #虚拟主机2, you can configure multiple virtual hosts at the same time server{  listen       8080;  server_name  localhost;  Location/{     root   d:/xiangmu/txym_web;     Index  index.html index.htm;}}}  

See the configuration of this virtual host, I believe the configuration of Tomcat or Apache people are very familiar with the feeling. This concludes with an update of the configuration under Linux, the deployment of PHP and Python projects, reverse proxies and load balancing, and the deployment of Java projects with Tomcat.

Installation and simple configuration of nginx in Windows environment

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.