Porting nginx to Windows for Development Environment

Source: Internet
Author: User
Tags openssl library

From: http://bbs.chinaunix.net.fastcdn.com/viewthread.php? Tid = 1328536

 

I don't have much memory on my computer. It's hard to run Apache for a long time. nginx eats memory just like Notepad, So I compile one for development.

Prerequisites:
Install cygwin and install GCC and G ++ (for installation, see http://www.xueler.com/docs/tool/###cygwin)
The gzip module requires the zlib library
The rewrite module requires the PCRE Library
Install PCRE and zlib before installing nginx
If you want to use SSL, you also need the OpenSSL library

  • 1. Download the source code nginx-0.7.24.tar.gz from nginx.net and store it under D: \ Linux \.
  • 2. Use cygwin to install nginx to D:/Server/nginx

Installation command

[Copy to clipboard] [-]

Code:

CD/cygdrive/D/Linux
Tar zxvf nginx-0.7.24.tar.gz
CD nginx-0.7.24
./Configure -- prefix =/cygdrive/D/Server/nginx -- With-CC-opt = "-D fd_setsize = 2048"
Make & make install

If you do not add-with-CC-opt = "-D fd_setsize = 2048", the nginx installation will display

16:34:56 [emerg] 2496 #0: the maximum number of files supported by select () is 64 error message, this indicates that the value of fd_setsize is greater than the value specified by the worker_connections command in the nginx configuration file. change the worker_connections option in conf to a smaller value. For example, if-with-CC-opt = "-dfd_setsize = 2048" is added, this problem will not occur.

  • 3. Copy the cygcrypt-0.dll, cygpcre-0.dll, cygwin1.dll, cygz. DLL to D: \ Server \ nginx \ sbin from the bin directory of cygwin.

Nginx compiled with cygwin requires these extensions to run independently of cygwin.

The installation is complete, and the configuration is as follows.
I won't talk about PHP and MySQL installation here. I used PHP to decompress it in D: \ Server \ PHP
If PHP and MySQL are not installed, nginx installation and configuration can still run static files.

  • 4. Configure nginx + PHP + MySql

I want to open a CGI process to listen for processing PHP scripts (a CGI process can be opened in Windows to solve the problem)
I want to start nginx and MySQL, And let nginx forward requests to PHP-CGI for processing.
I also need to conveniently disable PHP-CGI, nginx, and MySQL

Open in D:/Server/nginx/CONF/nginx. conf
This configuration file creates a default virtual host localhost. the root directory of the file is D:/Server/nginx/html/
Find index index.html index.htm;
Change to index index.html index.htm index. php;
Added nginx support for the default PHP Homepage
Remove the comments before the content similar to the following configurations and change them

Location ~ \. Php $ {
Root HTML;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param script_filename D:/Server/nginx/html $ fastcgi_script_name;
Include fastcgi_params;
}

  • 5. Create a nginx startup and shutdown script.

Create start. BAT and stop. BAT in D:/Server/nginx.
The content is as follows:
D:/Server/nginx/start. bat

[Copy to clipboard] [-]

Code:

@ Echo off
Echo PHP-CGI is starting...
Start/B d: \ Server \ PHP \ php-cgi.exe-B 127.0.0.1: 9000-C D: \ Server \ PHP. ini
Echo PHP-CGI startup completed...

Echo nginx is starting...
D:/Server/nginx/sbin/nginx.exe
Echo nginx startup completed...

Net start MySQL
ECHO started successfully

D:/Server/nginx/stop. bat

[Copy to clipboard] [-]

Code:

@ Echo off
Echo PHP-CGI is shutting down...
Tskill PHP-CGI
Echo PHP-CGI disabled

Echo nginx is shutting down...
Tskill nginx
Echo nginx disabled

Net stop MySQL
Echo MySQL disabled

Open D:/Server/nginx/start. BAT and D:/Server/nginx/stop. BAT to start and close nginx + PHP + MySQL (CGI) respectively.

Although nginx is compiled and installed, there are not many nginx codes, and it takes much longer to complete compilation and installation than to install Dreamweaver cs4.
Because the cygwin environment is used to compile the UNIX software to run in the window, the problem here is: we can only create a virtual host directory in D:/Server/nginx, web document files cannot be read outside of D:/Server/nginx.
Change configure

[Copy to clipboard] [-]

Code:

. /Configure -- prefix =/cygdrive -- http-FastCGI-temp-Path = D/Server/fastcgi_temp -- http-proxy-temp-Path = D/Server/proxy_temp -- http-client- body-temp-Path = D/Server/client_body_temp -- http-log-Path = D/Server/logs/access. log -- error-log-Path = D/Server/logs/error. log -- PID-Path = D/Server/logs/nginx. PID -- sbin-Path = D/Server/sbin/nginx -- conf-Path = D/Server/CONF/nginx. conf -- With-CC-opt = "-D fd_setsize = 2048"

Nginx can read partitions other than nginx prefix, but the partition name cannot contain: And can only use/, cannot use \
For example, to set root to E: \ Web, write it as root E/web.

Download nginx0.7.24 compiled and configured. The compiled file is very small, and the installation process file occupies space.

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.