Windows Nginx installation, configuration, and use _nginx

Source: Internet
Author: User
Tags memory usage openssl win32 nginx server

At present, the major domestic portal sites have been deployed nginx, such as Sina, NetEase, Tencent, etc. several important domestic video sharing sites have also deployed nginx, such as six rooms, cool 6. Recently found Nginx technology in the domestic increasingly hot, more and more sites began to deploy Nginx.

Compared with Apeach and Iis,nginx, the advantages of lightweight, high-performance, stable, simple configuration and less resource occupancy are popular.

1) Download Address:

http://nginx.org

2) Start

Extract to C:\nginx, run Nginx.exe (that is, nginx-c conf\nginx.conf), default to use 80 ports, log See folder C:\nginx\logs

3) Use

http://localhost

4) off

Nginx-s stop or taskkill/f/im nginx.exe > nul

5) Common Configuration

C:\nginx\conf\nginx.conf, use your own definition of conf file such as my.conf, command for Nginx-c conf\my.conf

  Common configurations are as follows:

Copy Code code as follows:
nginx.conf Code
HTTP {
server {
#1. Listening on port 80
Listen 80;
Location/{
# 2. The default home page directory is the HTML subdirectory of the Nginx installation directory.
root HTML;
Index index.html index.htm;
# 3. Lists files and subdirectories when there are no index pages
AutoIndex on;
Autoindex_exact_size on;
Autoindex_localtime on;
}
# 4. Specify a virtual directory
Location/tshirt {
Alias D:\programs\Apache2\htdocs\tshirt;
Index index.html index.htm;
}
}
# 5. Virtual Host Www.emb.info Configuration
server {
Listen 80;
server_name www.emb.info;
Access_log Emb.info/logs/access.log;
Location/{
Index index.html;
Root Emb.info/htdocs;
}
}
}

  
  Small tip:
run nginx-v to see which modules are supported by the WIN32 platform build. My results here are:
Log Code

Copy Code code as follows:
Nginx version:nginx/0.7.65
TLS SNI Support Enabled
Configure arguments:
--builddir=objs.msvc8
--crossbuild=win32
--with-debug--prefix=
--conf-path=conf/nginx.conf
--pid-path=logs/nginx.pid
--http-log-path=logs/access.log
--error-log-path=logs/error.log
--sbin-path=nginx.exe
--http-client-body-temp-path=temp/client_body_temp
--http-proxy-temp-path=temp/proxy_temp
--http-fastcgi-temp-path=temp/fastcgi_temp
--with-cc-opt=-dfd_setsize=1024
--with-pcre=objs.msvc8/lib/pcre-7.9
--with-openssl=objs.msvc8/lib/openssl-0.9.8k
--with-openssl-opt=enable-tlsext
--with-zlib=objs.msvc8/lib/zlib-1.2.3
--with-select_module
--with-http_ssl_module
--with-http_realip_module
--with-http_addition_module
--with-http_sub_module
--with-http_dav_module
--with-http_stub_status_module
--with-http_flv_module
--with-http_gzip_static_module
--with-http_random_index_module
--with-http_secure_link_module
--with-mail
--with-mail_ssl_module
--with-ipv6

Obviously, the most frequently used memcache, rewrite modules are not in it, so the Win32 compiled version can only be used for basic development testing, for the product platform, you should recompile the Win32 version you want, or more convenient to use under Linux.

6) View the Nginx process

Tasklist/fi "imagename eq nginx.exe", shown below:
Image name PID session name Session # Memory usage
========================= ======== ================ =========== ============
Nginx.exe 8944 Console 1 5,128 K
Nginx.exe 6712 Console 1 5,556 K

7) Nginx Common commands

Nginx-s stop forced shutdown
Nginx-s quit safe shutdown
Nginx-s Reload Change the configuration file, restart the Nginx worker process, when the configuration file comes into effect
Nginx-s Reopen open log file

8) Other

You can open multiple Nginx worker processes through a configuration file, but at the same time only one of the Nginx worker processes are working and other blocking waits.
A nginx worker process can handle up to 1024 connections at the same time.
Cache or modules that require shared memory in nginx cannot be used properly under Windows.
However, nginx officials are improving, and in the future Nginx will run as a service, using I/O completion ports instead of the Select method, enabling multiple worker processes to work concurrently.
To use Nginx with php-cgi, you need to modify the environment variables, otherwise, php-cgi run a certain number of launches, need to restart, set php_fcgi_max_requests this variable is 0.

The above is passed on the Win7.

8) Nginx starts as Windows service

1. Download Microsoft two tools:

Instsrv.exe Srvay.exe

2. Executive Order:

Instsrv Nginxc:/nginx/srvany.exe

3. Configure the Nginx running parameters

You can import the configuration directly into the registry

Windows Registry Editor Version 5.00

[Hkey_local_machine/system/currentcontrolset/services/nginx/parameters]
"Application" = "C://nginx//nginx.exe"
"Appparameters" = ""
"Appdirectory" = "c://nginx//"

Note: Many of the Nginx built-in module windows are not available, and are viewed with the nginx-v command.

9) Deploy Mono+asp.net environment under Nginx

1. Extract fastcgi-mono-server from Mono for Windows

2, Nginx nginx.conf configuration:

Copy Code code as follows:
Worker_processes 1;
Error_log Logs/error-debug.log Info;

Events {
Worker_connections 1024;
}

HTTP {
Include Mime.types;
Default_type Text/plain;
Sendfile on;

Keepalive_timeout 65;
Index index.html index.htm;

server {
Listen 80;
server_name yourdomain.com;
Index index.aspx Default.aspx;

Location/{
Root D:\www/yourwebapp;

Fastcgi_pass 127.0.0.1:8000;
Fastcgi_param script_filename $document _root/$fastcgi _script_name;
Include Fastcgi_params;
}
}
}

Extract the above fastcgi-mono-server, all files are registered to the GAC (otherwise the WEB application will not be able to find them, of course you can put it directly to Webapp/bin), and then extract to a folder, which is assumed to be d:/ Fastcgi-mono-server.

We can then run the FastCGI by following the command:
fastcgi-mono-server2/socket=tcp:127.0.0.1:8000/root= "D:\www\yourwebapp"/applications=yourdomain.com:/:. /multiplex=true

At the end of the run Nginx server, our asp.net program can be disconnected from IIS.

The above is the entire content of this article, I hope to give you a reference, but also hope that we support the cloud habitat community.

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.