Installing and configuring Nginx under Windows
Http://jingyan.baidu.com/article/f3e34a12a9c1c3f5eb6535d4.html
1):
http://nginx.org
2) Start
Extract to C:\nginx, run Nginx.exe (i.e. nginx-c conf\nginx.conf), default to 80 port, log see folder C:\nginx\logs
3) Use
http://localhost
4) Close
Nginx-s stop or taskkill/f/im nginx.exe > nul
5) Common Configuration
C:\nginx\conf\nginx.conf, use your own defined conf file such as my.conf, command for Nginx-c conf\my.conf
Common configurations are as follows:
nginx.conf Code
HTTP {
server {
#1. Listening on port 80
Listen 80;
Location/{
# 2. The default home directory is the HTML subdirectory of the Nginx installation directory.
root HTML;
Index index.html index.htm;
# 3. Lists files and subdirectories when no index pages are available
AutoIndex on;
Autoindex_exact_size on;
Autoindex_localtime on;
}
# 4. Specify the 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;
}
}
}
HTTP {
server {
#1. Listening on port 80
Listen 80;
Location/{
# 2. The default home directory is the HTML subdirectory of the Nginx installation directory.
root HTML;
Index index.html index.htm;
# 3. Lists files and subdirectories when no index pages are available
AutoIndex on;
Autoindex_exact_size on;
Autoindex_localtime on;
}
# 4. Specify the 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;
}
}
}
Tips:
Run nginx-v to see which modules are supported by the WIN32 platform's compiled version. My results here are:
Log Code
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
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 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 takes effect
Nginx-s Reopen open log file
8) Other
Multiple Nginx worker processes can be opened through a configuration file, but at the same time only one of the Nginx worker processes is working, other blocking waits.
An nginx worker process can handle up to 1024 connections at a time.
The cache or module that requires shared memory in Nginx cannot be used properly under Windows.
However, Nginx official is improving, in the future Nginx will run as a service, using I/O completion ports instead of the Select method, so that multiple worker processes can work concurrently.
To use Nginx with php-cgi, you need to modify the environment variables, otherwise, php-cgi run a certain number of times to launch, need to restart, set php_fcgi_max_requests this variable is 0.
The above is passed on the Win7.
8) Nginx starts in Windows service mode
1. Download Microsoft two tools:
Instsrv.exe Srvay.exe
2. Execute the command:
Instsrv Nginxc:/nginx/srvany.exe
3. Configure the Nginx operating 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: The Nginx built-in module is not available under Windows, and is viewed with the nginx-v command.
9) Deploy Mono+asp.net environment under Nginx
1. Extracting fastcgi-mono-server from Mono for Windows
2, the configuration of Nginx nginx.conf:
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 find them, of course, you can also be placed directly into the Webapp/bin), and then extracted to a folder, which is assumed to be d:/ Fastcgi-mono-server.
Then we can run FastCGI as follows:
fastcgi-mono-server2/socket=tcp:127.0.0.1:8000/root= "D:\www\yourwebapp"/applications=yourdomain.com:/:. /multiplex=true
Nginx Configuration and Common commands