For its users and applications, each VPS platform runs and manages exactly the same as a stand-alone host, because each VPS can be restarted independently and has its own root access, user, IP address, memory, process, file, application, System function library, and configuration file.
VPS Server is the most important indicator of memory size, multiple VPS servers can share a CPU, but can not share the same block of memory. The greater the memory, the more expensive the price.
Below, take the VPS where my blog is located for example, to introduce the optimization of Nginx 0.7.x + PHP 5.2.6 (FastCGI) + MySQL 5.1 under 128M RAM.
As for Nginx + PHP + MySQL installation configuration, see: "Nginx 0.7.x + php 5.2.6 (FastCGI) to build 10 times times more than Apache Web Server (4th edition)"
--------------------------------------------------------------------------------
Optimized effect:
The 1 Nginx processes that provide HTTP services occupy 11M of physical memory, 5 php-cgi processes each occupy 8M of physical memory, 1 MySQL servers occupy 7M physical memory, plus two memory-intensive Nginx and php-cgi parent processes, Nginx + PHP + The MySQL series takes up only 47.7% of physical memory, or 62M of physical memory (128M * 47.7%≈62m).
In addition, the VPS server system itself and other programs will also use some memory, but 128M memory VPS is sufficient. Overall, after optimized, 128M memory VPS Run Nginx + PHP + MySQL effect is good. Of course, if you have money to buy a larger memory vps, it would be better.
the optimizations are as follows:
One, add 256M swap file
1, create and activate swap file
cd/var/
DD If=/dev/zero of=swapfile bs=1024 count=262144
/sbin/mkswap Swapfile
/sbin/swapon Swapfile
2, add to the Fstab file to allow the system to boot automatically
Vi/etc/fstab
Add the following at the end:
Reference
/var/swapfile Swap Defaults 0 0
See:
--------------------------------------------------------------------------------
Nginx 0.7.19 Main configuration file (nginx.conf) optimization
Copy Code code as follows:
User www www.
#Nginx每个进程耗费10M ~12m memory, this only opens a nginx process, saving memory.
Worker_processes 1;
Error_log/data1/logs/nginx_error.log Crit;
Pid/usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors the can is 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 32k;
Large_client_header_buffers 4 32k;
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;
#对网页文件, CSS, JS, XML and so on to start gzip compression, reduce data transmission, improve access speed.
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;
#limit_zone crawler $binary _remote_addr 10m;
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;
Rewrite static of 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/([0-9]+) _ ([0-9]+) _ ([0-9]+). htm$/read.php?$1&page=$2&part=$3 last;
Rewrite ^/index_ ([0-9]+) _ ([0-9]+). htm$/index.php?mode=$1&page=$2 last;
Rewrite ^/star_ ([0-9]+) _ ([0-9]+). htm$/star.php?mode=$1&page=$2 last;
Rewrite ^/category_ ([0-9]+). htm$/index.php?go=category_$1 last;
Rewrite ^/category_ ([0-9]+) _ ([0-9]+) _ ([0-9]+). 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_ ([0-9]+) _ ([0-9]+) _ ([0-9]+) _ ([0-9]+). htm$/index.php?go=archive&cm=$1&cy=$2&mode=$3 &page=$4 last;
Rewrite ^/showday_ ([0-9]+) _ ([0-9]+) _ ([0-9]+). htm$/index.php?go=showday_$1-$2-$3 last;
Rewrite ^/showday_ ([0-9]+) _ ([0-9]+) _ ([0-9]+) _ ([0-9]+) _ ([0-9]+). htm$/index.php?go=showday_$1-$2-$3&mode=$4 &page=$5 last;
Location ~. *\. (PHP|PHP5)? $
{
#将Nginx与FastCGI的通信方式由TCP改为Unix Socket. TCP is more stable than UNIX sockets under high concurrent access, but UNIX sockets are faster than TCP.
Fastcgi_pass Unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include fcgi.conf;
}
Location ~/read.php
{
#将Nginx与FastCGI的通信方式由TCP改为Unix Socket. TCP is more stable than UNIX sockets under high concurrent access, but UNIX sockets are faster than TCP.
Fastcgi_pass Unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include fcgi.conf;
}
#博客的图片较多, fewer changes, caching them locally in the browser for 15 days, can increase the speed of the next page that opens my blog.
Location ~. *\. (gif|jpg|jpeg|png|bmp|swf) $
{
Expires 15d;
}
#博客会加载很多JavaScript, CSS, they are cached in the browser local cache for 1 days, visitors to read an article or a page, and then look at another file or another page of content, without downloading the same JavaScript, CSS from the server again, improve 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;
}
}
Current 1/2 page
12 Next read the full text