Nginx is a lightweight, high-performance Http WebServer, written in an event-driven manner, so nginx is more stable, better performing, simpler to configure, and less resource-intensive than Apache.
1. Installing Nginx
From v0.7.52 onwards, Nginx started to release the Windows version of Nginx, you can download on its official website: http://nginx.net
After downloading, unzip directly, here unzip to C:\nginx directory.
2. Start Nginx
The command line enters the C:\nginx directory, runs Nginx.exe, and starts the console window. Port 80 is enabled by default. People who have used Tomcat want to be able to see the boot log in the console, and the Nginx log has to look at the corresponding log file in the logs directory.
3. Visit the Welcome HTML page
By accessing http://localhost in the browser, you can see the default welcome page.
4. Stop Nginx
CTRL + C didn't respond. The console window is then closed. But the re-visit to http://localhost still works. Review the process and discover that Nginx was not shut down at all. So if you want to shut down nginx completely, it should be
Command code
- Nginx-s stop
Please refer to official document Nginx/windows usage
Or use the Windows Taskkill command (recommended below):
Command code
- taskkill/f/im nginx.exe > nul
5. Ngnix Common Configuration
All Nginx configurations Use the conf/nginx.conf file by default, which is equivalent to the Apache httpd.conf file. When running the Nginx.exe implication runs the nginx-c conf\nginx.conf. If you want to use your own defined conf file such as my.conf, the command is Nginx-c conf\my.conf.
Common configurations are as follows:
nginx.conf Code
- HTTP {
- server {
- #1. Listening on 80 ports
- Listen 80;
- Location/{
- # 2. The default home directory is in the HTML subdirectory of the Nginx installation directory.
- root HTML;
- Index index.html index.htm;
- # 3. list files and subdirectories when no index page is 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. $
- 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=1024x768
- --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.
Nginx-windows under Nginx Basic installation and configuration