Install configure and use nginx under windows
- 2020-05-10 23:32:12
- OfStack
At present, domestic major web portals have deployed Nginx, such as sina, netease, tencent, etc. Several important video sharing websites in China have also deployed Nginx, such as 6 room and 6 cool. The newly discovered Nginx technology is becoming increasingly popular in China, and more and more websites are starting to deploy Nginx.
Compared with apeach and iis, is widely welcomed for its advantages of lightweight, high performance, stability, simple configuration and low resource utilization.
1) download address:
http: / / nginx org
2) start
Unzip to c:\nginx, run nginx.exe (i.e. nginx-c conf\ nginx.conf), default port 80, log in folder C:\nginx\logs
3) use
http: / / localhost
4) closed
nginx-s stop or taskkill /F /IM nginx.exe > nul
5) common configuration
C:\nginx\conf\ nginx.conf, using a self-defined conf file such as my.conf, command nginx-c conf\ my.conf
Common configurations are as follows:
Nginx.conf code
http {
server {
#1. To listen to 80 port
listen 80;
location / {
# 2. The default home page directory is in nginx Installation directory html Subdirectories.
root html;
index index.html index.htm;
# 3. Lists files and subdirectories when there is no index page
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;
}
}
}
Tip:
Running nginx-V allows you to see which modules are supported by the compiled version of the Win32 platform. The result here is:
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
Obviously, the most frequently used memcache and rewrite modules are not included, so the compiled version of win32 can only be used for basic development testing. For the production platform, you should recompile the version of win32 you want, or it is more convenient to use under linux.
6) view the nginx process
tasklist /fi "imagename eq nginx ", as shown below:
The image name is 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 shut down safely
When nginx-s reload changes the configuration file, restart the nginx worker process and the configuration file takes effect
nginx-s reopen open the log file
8) other
Multiple nginx worker processes can be started from the configuration file, but only one of the nginx worker processes is working at the same time, and the rest are blocked and waiting.
One nginx worker process can handle up to 1024 connections at a time.
cache or modules that require Shared memory in nginx cannot be used properly under windows.
However, nginx officials are working on improvements, and in the future nginx will run as a service, using I/O completion ports instead of select, enabling multiple worker processes to work concurrently.
To use nginx in conjunction with php-cgi, the environment variable needs to be modified; otherwise, php-cgi will be launched after running 1 for a certain number of times, and it needs to be restarted. Set PHP_FCGI_MAX_REQUESTS as 0.
The above is passed on win7.
8) nginx starts as an windows service
1. Download two Microsoft tools:
instsrv. exe srvay exe
2. Execute the order:
instsrv Nginxc: / nginx srvany exe
3. Configure the running parameters of Nginx
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: Nginx under windows has a lot of module built-in module missing, check 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. Configuration of 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;
}
}
}
extracts the above FastCGI-Mono-Server, registers all the files to GAC(otherwise you will not find them in webapp/bin), and then unzips them to a folder, 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
Finally, run the Nginx server and our ASP.Net program will be disconnected from IIS.