Nginx 0.7.x + PHP 5.2.6 (FastCGI) + MySQL 5.1 configuration optimization on 1/2 M small memory VPs Server Page

Source: Internet
Author: User
Tags vps root access vps server

Users and Applications Program The operation and management of each VPs platform is identical to that of an independent host, each VPs can be restarted independently and has its own root access permissions, users, IP addresses, memory, processes, files, applications, system function libraries, and configuration files.
The most important indicator of a VPs server is the memory size. Multiple VPs servers can share one CPU, but cannot share the same memory. The larger the memory, the more expensive the price is.
The following uses the VPs of my blog as an example to describe how to optimize nginx 0.7.x + PHP 5.2.6 (FastCGI) + MySQL 5.1 in MB of memory.
For the installation and configuration of nginx + PHP + MySQL, see nginx 0.7.x + PHP 5.2.6 (FastCGI) build a web server that is 10 times better than Apache (version 4th).
--------------------------------------------------------------------------------
Optimized results:
One nginx process that provides the HTTP service occupies 11 MB of physical memory, five PHP-CGI processes occupy about 8 MB of physical memory, and one MySQL Server occupies 7 MB of physical memory, with two nginx and PHP-CGI parent processes that occupy a small amount of memory, the nginx + PHP + MySQL series only occupy 47.7% of the physical memory, that is, 62m physical memory (128 M * 47.7% ≈ 62 m ).

In addition, the VPs server system itself and other programs will also use some memory, but the VPs with M memory is enough. In general, after optimization, the VPs with MB of memory runs nginx + PHP + MySQL with good results. Of course, it would be better if you have money to buy VPs with larger memory.
The optimization items are as follows:
1. Add M swap files
1. Create and activate swap files
CD/var/
Dd If =/dev/Zero of = swapfile BS = 1024 COUNT = 262144
/Sbin/mkswap swapfile
/Sbin/Swapon swapfile
2. Add it to the fstab file to enable automatic startup during system boot.
VI/etc/fstab
Add the following content at the end:
Reference
/Var/swapfile swap defaults 0 0
For details, see:
--------------------------------------------------------------------------------
Ii. nginx 0.7.19 main configuration file (nginx. conf) Optimization CopyCode The Code is as follows: User WWW;
# Nginx each process consumes 10 MB ~ MB memory. Only one nginx process is enabled to save memory.
Worker_processes 1;
Error_log/data1/logs/nginx_error.log crit;
Pid/usr/local/webserver/nginx. PID;
# Specifies the value for maximum file descriptors that can be opened by this process.
Worker_rlimit_nofile 51200;
Events
{
Use epoll;
Worker_connections 51200;
}
HTTP
{
Include mime. types;
Default_type application/octet-stream;
# Charset gb2312;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32 K;
Large_client_header_buffers 4 32 K;
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;
# Enable gzip compression for webpage files, CSS, JS, and XML to reduce data transmission volume and increase access speed.
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;
# Limit_zone crawler $ binary_remote_addr 10 m;
Server
{
Listen 80;
SERVER_NAME blog.s135.com www.s135.com s135.com * .s135.com;
Index index.html index.htm index. php;
Root/data0/htdocs/blog;
# Limit_conn crawler 20;
# Static rewrite for the bo-Blog system
Rewrite ^/post/(%0-9%%%%.htm $/read. php? $1 last;
Rewrite ^/post/(%0-9%%%%_(%0-9%%%%%%.htm $/read. php? $1 & page = $2 last;
Rewrite ^/post/(1_0-91_1_1_1__(1_0-91_1_1__(1_0-91_1_1_1_.htm $/read. php? $1 & page = $2 & Part = $3 last;
Rewrite ^/index_(1_0-91_1_1_1__(1_0-91_1_1_.htm $/index. php? Mode = $1 & page = $2 last;
Rewrite ^/star_(1_0-91_1_1_1__(1_0-91_1_1_.htm $/star. php? Mode = $1 & page = $2 last;
Rewrite ^/category_(%0-9%%%%%.htm $/index. php? Go = Category _ $1 last;
Rewrite ^/category_(1_0-91_1_1_1__(1_0-91_1_1_1__(1_0-91_1_1_1_.htm $/index. php? Go = Category _ $1 & mode = $2 & page = $3 last;
Rewrite ^/archive_(%0-9%%%%%_(%0-9%%%%%%.htm $/index. php? Go = Archive & CM = $1 & Cy = $2 last;
Rewrite ^/archive_(1_0-91_1_1_1__(1_0-91_1_1_1__(1_0-91_1_1_1_1__(1_0-91_1_1_1_.htm $/index. php? Go = Archive & CM = $1 & Cy = $2 & mode = $3 & page = $4 last;
Rewrite ^/showday_(1_0-91_1_1_1__(1_0-91_1_1_1__(1_0-91_1_1_1_.htm $/index. php? Go = showday _ $1-$2-$3 last;
Rewrite ^/latest $/index. php? Go = showday _ $1-$2-$3 & mode = $4 & page = $5 last;
Location ~ . * \. (PhP | PhP5 )? $
{
# Change the communication mode between nginx and FastCGI from TCP to UNIX socket. TCP is more stable than UNIX socket in High-concurrency access, but UNIX socket is faster than TCP.
Fastcgi_pass Unix:/tmp/php-cgi.sock;
# Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fcinclude gi. conf;
}
Location ~ /Read. php
{
# Change the communication mode between nginx and FastCGI from TCP to UNIX socket. TCP is more stable than UNIX socket in High-concurrency access, but UNIX socket is faster than TCP.
Fastcgi_pass Unix:/tmp/php-cgi.sock;
# Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fcinclude gi. conf;
}
# The number of blog images is large and the number of changes is small. caching them locally in the browser for 15 days can increase the loading speed of my blog page next time.
Location ~ . * \. (GIF | JPG | JPEG | PNG | BMP | SWF) $
{
Expires 15d;
}
# The blog will load a lot of JavaScript and CSS and cache them locally in the browser for one day. After reading an article Article After one page, you can view the content of another file or another page without downloading the same JavaScript and CSS from the server, which improves the page display speed.
Location ~ . * \. (JS | CSS )? $
{
Expires 1D;
}
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/data1/logs/access. Log Access;
}
}

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.