Before giving you a detailed introduction to Linux Nginx, let's first get to know about Linux Nginx and then give a full introduction to Linux Nginx. Using Linux Nginx to build a high-performance Web Environment Linux Nginx ("engine x") is a high-performance HTTP and reverse proxy server and an IMAP/POP3/SMTP proxy server. Linux Nginx is 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.
As Linux Nginx outperforms Apache's high performance and stability, more and more websites are using Linux Nginx as Web servers in China, including Sina Blog, Sina podcast, Netease news and other portal website channels, 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 to smoothly change the php. ini configuration without restarting php-cgi: http://php-fpm.anight.org/
- Note: For PHP scripts and fpmscripts, 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 Linux 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 nginxkill-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 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 "exportPATH= $ 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<Value Name="Listen_address">IP: 9000</Value>
// Use the default 127.0.0.1 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>// Comment out
- (4)<Value Name="Group">Nobody</Value>// Comment out
- (5)<Value Name="Allowed_clients">127.0.0.1</Value>// For a PC that can be connected, 127.0.0.1 is used on the local machine.
Start php-fpm #/usr/local/php/sbin/php-fpm start and add it to self-start # echo "/usr/local/php/sbin/php-fpm start"> /etc/rc. local
5. modify the configuration file of Linux Nginx 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 32k;
- large_client_header_buffers 4 32k;
- client_max_body_size 8m;
- 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 64k;
- fastcgi_buffers 4 64k;
- fastcgi_busy_buffers_size 128k;
- fastcgi_temp_file_write_size 128k;
- gzip on;
- gzip_min_length 1k;
- gzip_buffers 4 16k;
- 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 1h;}
- 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 the PHP virtual host 127.0.0.1: 9000 is the fastcgi PC. Here I use the local/var/www/blog $ fastcgi_script_name; the directory test configuration file saved on the PHP web page:
#/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=500065000
Make the configuration take effect immediately: #/sbin/sysctl-p.
- Nginx. conf configuration in Linux is highly efficient
- Install and compile MySQL 5.1.34 extension library and Php Web server in Linux Nginx
- View the default Linux samba version.
- Linux mounting Windows partition Disk
- Linux YUM is built on an ftp server as the source