Document directory
- 1. Installation
- 1. 2. Management
- 2. 1. Install spawn-FastCGI of Lighttpd
- 2. Install the FastCGI Library
- 2.3.hello world
- 2. 4. Start spawn-CGI
- 2. 5. Modify the nginx configuration file
Below is a document I wrote a long time ago and posted it. 1. Install nginx1.1.
- Nginx Chinese wiki http://wiki.codemongers.com/nginxchsdownload nginx 0.6.26 (Development version) (Please download the latest version)
- Tar zxvf nginx-0.6.26.tar.gz
- ./Configure. Pay attention to items similar to checking for ***... Not found. It may be that the dependency package does not exist, so you need to install the dependency package.
- The PCRE is missing and sudo apt-Get install PCRE is installed. Or go to: http://www.pcre.org/
- If OpenSSL is missing, sudo apt-Get install libssl-Dev, or go to: http://www.openssl.org
- If zlib is missing, you can apt-Get install zlib1g, or http://www.zlib.net/
- For configuration instructions, see http://wiki.codemongers.com/nginxchsinstall. you can select the installation module.
- Make & make install
- Installed in/usr/local/nginx by default
1. 2. Management
- Execution options
-C </path/to/config> specifies a configuration file for nginx to replace the default one.
-T does not run, but only tests the configuration file. Nginx checks the syntax of the configuration file and tries to open the file referenced in the configuration file.
-V displays the nginx version.
-V displays the nginx version, compiler version, and configuration parameters.
- Check the configuration file
$ sudo nginx -t2008/03/12 19:15:11 info 12384#0: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok2008/03/12 19:15:11 info 12384#0: the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
- Start
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
- View nginx master process number
$ ps -ef | grep "nginx: master process"
| grep -v "grep"
| awk -F ' ' '{print $2}
26010
- Reload the configuration file
$sudo kill -HUP 26010
Control nginx through System Signal
You can use a signal system to control the main process. By default, nginx writes the PID of the main process to the/usr/local/nginx/logs/nginx. PID file. You can change the file location by passing the parameter to./configure or using the PID command.
The main process can process the following signals:
| Command |
Description |
Remarks |
| Term, int |
Close quickly |
|
| Quit |
Easy to close |
|
| Hup |
Reload Configuration |
Start a new working process with a new configuration and close the old working process with ease. |
| Usr1 |
Re-open the log file |
|
| Usr2 |
Smooth upgrade of executable programs |
|
| Winch |
Close the Working Process with ease |
|
- Default directory
Main Directory:/usr/local/nginx/
Configuration Directory:/usr/local/nginx/CONF/
Root directory:/usr/local/nginx/html/
Executable File Path:/usr/local/nginx/sbin/
2. fastcgi2.1. install spawn-FastCGI of Lighttpd
Download http://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz
./configure make cp ./src/spawn-fcgi /usr/local/nginx/sbin/
2. Install the FastCGI Library
Download http://www.fastcgi.com/dist/fcgi.tar.gz
./configure make make install
2.3.hello world
#include <iostream>#include <fcgi_stdio.h>
using namespace std;
int main(){
/* Initialization Code */
int count = 0;
/* Start of response loop */
while (FCGI_Accept() >= 0)
{
//* body of response loop /*/
printf("Content-type: text/html/r/n" "/r/n" ""
"FastCGI Hello/! (C, fcgi_stdio library)" "Request number %d running on host %s " "Process ID: %d/n", /++count, getenv("SERVER_NAME"), getpid()); }
/* End of response loop */ return 0;
}
Fastcgisameple after compilation
2. 4. Start spawn-CGI
/usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 25 -u www -f /usr/local/nginx/fcgi/FactCGISample
2. 5. Modify the nginx configuration file
VI/usr/local/nginx/CONF/nginx. conf
location ~ /.cgi$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
Don't forget to reload the configuration file.
$sudo kill -HUP 26010
Open the browser and enter http: // localhost/1.cgito display
FastCGI Hello! (C, fcgi_stdio library)Request number 1 running on host localhost Process
ID: 25473
3. webbench stress testing tool
Download: http://home.tiscali.cz: 8080 /~ Cz210552/distfiles/webbench-1.5.tar.gz
Installation:
tar zxvf webbench-1.5.tar.gzcd webbench-1.5
make && make install
Usage:
webbench -c 500 -t 30 http://127.0.0.1/test.jpg
500 is the number of concurrent connections, and 30 is the unit of time is second.
The result of testing with AB seems to have good performance on my virtual machine.
(Apache Plugin is an Apache toolkit)
AB-N 10000-C 100 http: // 127.0.0.1/1.cgi
This is apachetings, Version 2.3 <$ revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to the Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (Be patient)
Completed1000 requests
Completed2000 requests
Completed3000 requests
Completed4000 requests
Completed5000 requests
Completed6000 requests
Completed7000 requests
Completed8000 requests
Completed9000 requests
Completed10000 requests
Finished 10000 requests
Server Software: nginx/0.7.38
Server Hostname: 127.0.0.1
Server port: 80
Document path:/1.cgi
Document length: 143 bytes
Concurrency level: 100
Time taken for tests: 3.982 seconds
Complete requests: 10000
Failed requests: 8399
(CONNECT: 0, receive: 0, Length: 8399, exceptions: 0)
Write errors: 0
Total transferred: 2658399 bytes
HTML transferred: 1438399 bytes
Requests per secondd: 2511.06 [#/sec] (mean)
Time per request: 39.824 [MS] (mean)
Time per request: 0.398 [MS] (mean, internal SS all concurrent requests)
Transfer Rate: 651.89 [Kbytes/sec] canceled ed
Connection times (MS)
Min mean [+/-SD] median Max
Connect: 0 1 4.6 0 51
Processing: 22 39 6.8 36 93
Waiting: 4 39 6.8 36 93
Total: 24, 39, 8.2, 36, 97
Percentage of the requests served within a certain time (MS)
50% 36
66% 39
75% 41
80% 42
90% 48
95% 54
98% 70
99% 84
100% 97 (longest request)
4. nginx Module
Module list
Http://wiki.codemongers.com/NginxModules
Source code of the FastCGI module: nginx/src/HTTP/modules/ngx_http_fastcgi_module.c