It is said that nginx is a rising star of web servers over the past few years. It is an Apache killer, written by Russian programmers. It is a lightweight Web server. It is also said that it consumes less resources and is highly concurrent. In some cases, the efficiency is 10 times higher than that of Apache. Many large portal sites are used at home and abroad.
I decided to install and try it in Windows Server 2003 and integrate it with PHP.
As of the end of May 2010, the latest version of nginx is 0.8.38, you can go to the http://www.nginx.org/download.
Unzip PHP to C:/php-5.3.2-Win32-VC6-x86/and configure the php. ini file correctly.
Directly decompress the downloaded nginx-0.8.38.zip file to C:/nginx-0.8.38/, folder structure:
Conf/
Contrib/
Docs/
Html/
Logs/
Temp/
Nginx.exe
Nginx starts to provide services by running the nginx.exe file in double-click mode.
Html/folder is the default root directory of the website.
Conf/place nginx configuration-related files. The content of nginx. conf in the configuration file is as follows (the # hitting statement is commented out. For details, refer ):
Server {......} The nginx HTTP service port (80 by default), domain name, Character Set, root folder, home page file, and so on.
The following section configures nginx to integrate with PHP in FastCGI mode, and "C:/nginx-0.8.38/html" indicates the root folder of the website:
Location ~ /. Php $ {
# Root HTML;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param script_filename C: // nginx-0.8.38/html $ fastcgi_script_name;
Include fastcgi_params;
}
# User nobody;
Worker_processes 1;
# Error_log logs/error. log;
# Error_log logs/error. Log notice;
# Error_log logs/error. Log Info;
# PID logs/nginx. PID;
Events {
Worker_connections 1024;
}
HTTP {
Include mime. types;
Default_type application/octet-stream;
# Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'
# '$ Status $ body_bytes_sent "$ http_referer "'
# '"$ Http_user_agent" "$ http_x_forwarded_for "';
# Access_log logs/access. Log main;
Sendfile on;
# Tcp_nopush on;
# Keepalive_timeout 0;
Keepalive_timeout 65;
# Gzip on;
Server {
Listen 80;
SERVER_NAME localhost;
# Charset koi8-r;
# Access_log logs/host. Access. Log main;
Location /{
Root HTML;
Index index.html index.htm;
Autoindex on;
}
# Error_page 404/404 .html;
# Redirect server error pages to the static page/50x.html
#
Error_page 500 502 503 x.html;
Location =/50x.html {
Root HTML;
}
# Proxy the PHP scripts to Apache listening on 127.0.0.1: 80
#
# Location ~ /. Php $ {
# Proxy_pass http: // 127.0.0.1;
#}
# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ /. Php $ {
# Root HTML;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param script_filename C: // nginx-0.8.38/html $ fastcgi_script_name;
Include fastcgi_params;
}
# Deny access to. htaccess files, if Apache's document root
# Concurs with nginx's one
#
# Location ~ //. Ht {
# Deny all;
#}
}
# Another virtual host using mix of IP-, name-, and port-Based Configuration
#
# Server {
# Listen 8000;
# Listen somename: 8080;
# SERVER_NAME somename alias another. Alias;
# Location /{
# Root HTML;
# Index index.html index.htm;
#}
#}
# HTTPS Server
#
# Server {
# Listen 443;
# SERVER_NAME localhost;
# SSL on;
# Ssl_certificate cert. pem;
# Ssl_certificate_key cert. Key;
# Ssl_session_timeout 5 m;
# Ssl_protocols SSLv2 SSLv3 tlsv1;
# Ssl_ciphers all :! ADH :! Export56: RC4 + RSA: + high: + medium: + low: + SSLv2: + exp;
# Ssl_prefer_server_ciphers on;
# Location /{
# Root HTML;
# Index index.html index.htm;
#}
#}
}
In this case, open the browser on the local machine and browse http: // localhost. The message "Welcome to nginx!" is displayed !", The content is from the index.html file in HTML.
To really work with PHP, you must also run the PHP php-cgi.exe program. The way is, in the Command window, switch to the folder where the php-cgl.exe is located, run the C:/php-5.3.2-Win32-VC6-x86, run the php-cgi.exe-B 127.0.0.1: 9000 command, that is:
C:/php-5.3.2-Win32-VC6-x86> php-cgi.exe-B 127.0.0.1: 9000
Here 127.0.0.1: 9000 is the one we configured in the nginx. conf file, and the port number must be the same.
The order of running nginx.exe and php-cgi.exe commands does not affect the parsing of PHP files.
In this case, place a XXX. php file in the root directory and enter http: // localhost/xxx. php in the address bar of the browser. The result is displayed. Recommended file content:
<? PHP
Phpinfo ();
?>
We can see a lot of useful information about the PHP environment.
Nginx can also be configured to implement reverse proxy, multiple virtual hosts, URL redirection, and other functions.
Author: Zhang Qing (mesh) Xi'an PHP Education and Training Center
From mesh horizon: http://blog.why100000.com
Why 100,000 computer learning networks: http://www.why100000.com