Nginx ("engine X") is a high-performance HTTP and reverse proxy server and an IMAP/POP3/SMTP proxy server. Nginx was developed by the rambler.ru site with the highest access volume in Russia as Igor Sysoev. It has been running on this site for more than two and a half years. Igor publishes source code in the form of a class BSD license.
Nginx surpasses Apache's high performance and stability, making it more and more websites using nginx as web servers in China, including portal website channels such as Sina Blog, Sina podcast, and Netease news, discuz! Well-known forums such as official forums and the Shui Mu community, and emerging Web 2.0 websites such as Douban, yupoo album, domestic SNS, and thunder online.
Lab Environment
Centos4.5
Pcre-7.8.tar.gz Regular Expression
: Ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
Nginx-0.7.26.tar
: Http://www.nginx.net/
Php-5.2.6.tar.bz2
: Http://www.php.net/releases/
Php-5.2.6-fpm-0.5.9.diff.gz
Php-FPM is a FastCGI management patch for PHP. It can smoothly change the php. ini configuration without restarting PHP-CGI.
: Http://php-fpm.anight.org/
Note: The PHP version must be the same as that of FPM.
Mysql-5.0.67.tar.gz
Discuz! _6.0.0_ SC _utf8.zip
1. Install PCRE
# Tar-zxvf pcre-7.8.tar.gz
# Cd pcre-7.8
#./Configure
# Make & make install
2. Install nginx
# Tar-zxvf nginx-0.7.26.tar.gz
# Cd nginx-0.7.26
#./Configure -- prefix =/usr/local/nginx
# Make & make install
Start nginx
#/Usr/local/nginx/sbin/nginx
Stop nginx
# Kill-Quit 'cat/usr/local/nginx/logs/nginx. pid'
Restart nginx
Kill-HUP 'cat/usr/local/nginx/logs/nginx. pid'
Add to auto-start
# Echo "/usr/local/nginx/sbin/nginx">/etc/rc. Local
3. Install MySQL
# Tar-zxvf mysql-5.0.67.tar.gz
# Cd mysql-5.0.67
# Groupadd MySQL
# Useradd-G mysql-S/sbin/nologin-M MySQL
#. /Configure -- prefix =/usr/local/MySQL -- With-charset = GBK -- With-extra-charset = all -- enable-hread-safe-client -- enable-local-infile -- with-low-memory
# Make & make install
# Cp support-files/my-medium.cnf/etc/My. CNF
# Chown-r mysql. MySQL/usr/local/MySQL/
#/Usr/local/MySQL/bin/mysql_install_db -- user = MySQL
# Chown-r root. Root/usr/local/MySQL/
# Chown-r mysql. MySQL/usr/local/MySQL/var/
Start the Database Service and add it to auto-start
#/Usr/local/MySQL/bin/mysqld_safe -- user = MySQL &
# Cp support-files/MySQL. Server/etc/rc. d/init. d/mysqld
# Chmod 755/etc/rc. d/init. d/mysqld
Add to auto start service queue:
# Chkconfig -- add mysqld
# Chkconfig -- level 345 mysqld on
Add Root Password
#/Usr/local/MySQL/bin/mysqladmin-u Root Password "123456"
Test:
#/Usr/local/MySQL/bin/MySQL-u root-P
Enter the password 123456 to check whether the database can be accessed.
Configure the library file search path
# Echo "/usr/local/MySQL/lib/MySQL">/etc/lD. So. conf
# Ldconfig
# Ldconfig-V
Add/usr/local/MySQL/bin to the environment variable path.
# Echo "Export Path = $ path:/usr/local/MySQL/bin">/etc/profile
# Source/etc/profile
4. install PHP
An executable file is generated here, which is different from Apache. When combined with Apache, a dynamic library is generated.
# Tar-jxvf php-5.2.6.tar.bz2
# Gzip-CD php-5.2.6-fpm-0.5.9.diff.gz | patch-D php-5.2.6-p1
# Cd php-5.2.6
#. /Configure -- prefix =/usr/local/PHP -- With-mysql =/usr/local/MySQL -- enable-FastCGI -- enable-FPM -- With-config-file-Path =/ usr/local/PHP/etc -- enable-force-CGI-Redirect
# Make & make install
# Cp PHP. ini-recommended/usr/local/PHP/etc/PHP. ini
# Vi/usr/local/PHP/php-fpm.conf
(1) <value name = "listen_address"> 127.0.0.1: 9000 </value>
Change to <value name = "listen_address"> IP: 9000 </value> // The default 127.0.0.1 is used on the local machine.
(2) Remove comments and modify the following two lines.
<Value name = "sendmail_path">/usr/sbin/sendmail-t-I </value>
<Value name = "display_errors"> 1 </value>
(3) <value name = "user"> nobody </value> // uncomment
(4) <value name = "group"> nobody </value> // uncomment
(5) <value name = "allowed_clients"> 127.0.0.1 </value> // the PC to be connected to. This local machine uses 127.0.0.1.
Start PHP-FPM
#/Usr/local/PHP/sbin/PHP-FPM start
Add to auto-start
# Echo "/usr/local/PHP/sbin/PHP-FPM start">/etc/rc. Local
5. Modify the nginx configuration file and support PHP
# Vi/usr/local/nginx/CONF/nginx. conf
User nobody;
Worker_processes 8;
Pid/usr/local/nginx/logs/nginx. PID;
Worker_rlimit_nofile 1024;
Events
{
Use epoll;
Worker_connections 1024;
}
HTTP {
Include mime. types;
Default_type application/octet-stream;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32 K;
Large_client_header_buffers 4 32 K;
Client_max_body_size 8 m;
Sendfile on;
Tcp_nopush on;
Keepalive_timeout 60;
Tcp_nodelay on;
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 64 K;
Fastcgi_buffers 4 64 K;
Fastcgi_busy_buffers_size 128 K;
Fastcgi_temp_file_write_size 128 K;
Gzip on;
Gzip_min_length 1 K;
Gzip_buffers 4 16 K;
Gzip_http_version 1.0;
Gzip_comp_level 2;
Gzip_types text/plain application/X-JavaScript text/CSS application/XML;
Gzip_vary on;
Server {
Listen 80;
SERVER_NAME www.bbb.com;
Root/var/www/blog;
Index index.html index.htm index. php;
Location ~ . * \. (PhP | PhP5 )? $ {
Root HTML;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param script_filename/var/www/blog $ fastcgi_script_name;
Include fastcgi_params;
}
Location ~ . * \. (GIF | JPG | JPEG | PNG | BMP | SWF) $
{
Expires 30d;
}
Location ~ . * \. (JS | CSS )? $
{
Expires 1 h;
}
Log_format access' $ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for ';
Access_log/var/logs/access. Log Access;
}
}
Note:
The server part is a php vm.
127.0.0.1: 9000 is a FastCGI PC. The local machine I use here
/Var/www/blog $ fastcgi_script_name; directory saved for the PHP webpage
Test configuration file:
#/Usr/local/nginx/sbin/nginx-T
6. Optimize Linux Kernel Parameters
# Vi/etc/sysctl. conf
Add the following content at the end:
Net. ipv4.tcp _ fin_timeout = 30
Net. ipv4.tcp _ keepalive_time = 300
Net. ipv4.tcp _ syncookies = 1
Net. ipv4.tcp _ tw_reuse = 1
Net. ipv4.tcp _ tw_recycle = 1
Net. ipv4.ip _ local_port_range = 5000 65000
Make the configuration take effect immediately:
#/Sbin/sysctl-P