Rumah  >  Artikel  >  Operasi dan penyelenggaraan  >  Bagaimana untuk menyediakan pelayan WEB berprestasi tinggi dengan Linux+Nginx+Php

Bagaimana untuk menyediakan pelayan WEB berprestasi tinggi dengan Linux+Nginx+Php

WBOY
WBOYke hadapan
2023-05-20 23:19:551180semak imbas

nginx ("enjin x") ialah pelayan proksi http dan terbalik berprestasi tinggi, serta pelayan proksi imap/pop3/smtp. nginx telah dibangunkan oleh igor sysoev untuk rambler.ru, tapak kedua paling banyak dikunjungi di Rusia, di mana ia telah berjalan selama lebih dua setengah tahun. igor mengeluarkan kod sumber di bawah lesen seperti BSD. Walaupun masih dalam versi beta, nginx sudah terkenal dengan kestabilannya, set ciri yang kaya, fail konfigurasi sampel dan penggunaan sumber sistem yang rendah.

Langkah-langkah pemasangan

1. Susun dan pasang perpustakaan sokongan yang diperlukan untuk php5.2.9

tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure --prefix=/usr/local
make
make install
cd ../

tar zxvf libmcrypt-2.5.8. tar .gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable - ltdl-install
make
make install
cd ../../

tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so. 4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a / usr /lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/ lib /libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so. 2.0 .1 /usr/lib/libmhash.so.2.0.1

tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../


2. Susun dan pasang perpustakaan sambungan mysql 5.1.34

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar zxvf mysql-5.1.34.tar.gz
cd mysql-5.1.34/make && make install
chmod +w /usr/local/webserver/mysql
chown -r mysql:mysql /usr/local/webserver/mysql
cd ../

Pemasangan mysql diabaikan di sini


3 dan pasang php (mod fastcgi)

tar zxvf php-5.2.9.tar.gz

gzip -cd php-5.2.9-fpm-0.5.10.diff.gz | -d php -5.2.9 -p1
cd php-5.2.9/
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/ local/webserver /php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir=/usr/ local -- with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable -buang- laluan --dayakan-mod-selamat --dayakan-bcmath --dayakan-shmop --dayakan-sysvsem --dayakan-pengoptimuman-sebaris --dengan-curl --dengan-curlwrappers --dayakan-mbregex -- enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with- mhash -- enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl
make zend_extra_libs='-liconv'
make install
cp php.ini-dist /usr/ local/webserver /php/etc/php.ini
cd ../


4. Ubah suai fail konfigurasi php-fpm

rm - f /usr/ local/webserver/php/etc/php-fpm.conf

vi /usr/local/webserver/php/etc/php-fpm.conf

Masukkan yang berikut:




/usr /local/webserver/php/logs/php-fpm.pid
/usr/local/webserver/php/logs/php-fpm.lognotis
10
1m
5s
yes
<

default
127.0.0.1:9000

-1


0666
< /value>

/usr/sbin/sendmail -t -i
1

www
www

static
128< ;/value>

20
5< /value>
35


0s
0s
logs/slow.log
<
< value name="rlimit_files">51200

0


yes
500< /value>
127.0.0.1

$hostname
/usr/local/bin:/usr/bin:/bin
/tmp
/tmp
/tmp
$ostype
$machtype
2



五、创建www用建www用建

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www


六、编译安装nginx通过设定编译选项,你可以改变这个设定.装,如:

./configure --user= www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module

make && make install
cd ../


七、创建fcgi.conf文件

rm -f /usr/local/webserver/nginx/conf/fcgi.conf
vi /usr/local/webserver/nginx/conf/fcgi .conf

输入以下内容:

fastcgi_param gateway_interface cgi/1.1;
fastcgi_param server_software nginx;

fastcgi_param query_string $query_string;
fastcgi_param server_software nginx;

fastcgi_param query_string $query_string;

fastcgi_param request_method;panjang_kandungan_fastcgi_param $panjang_kandungan ;


nama fail_skrip_fastcgi_param $root_dokumen$nama_skrip_fastcgi;
nama_skrip_fastcgi_param $nama_skrip_fastcgi;
permintaan_fastcgi_param_uri $request_uri;
dokumen_fastcgi_param param document_root $document_root;
fastcgi_param server_protocol $server_protocol;

fastcgi_param remote_addr $remote_addr;
fastcgi_param remote_port $remote_port;
fastcgi_param server_addr $server_addr>;
fastcgi_param nama_pelayan gi_param $nama_pelayan;

# php sahaja, diperlukan jika php dibina dengan --enable-force-cgi-redirect

fastcgi_param redirect_status 200;


八、编辑nginx配置rm -f /usr/local/webserver/nginx/conf/nginx.conf

vi /usr/local/webserver/nginx/conf/nginx.conf


输入以下内宨:

pengguna www www;

worker_processes 8;

error_log /usr/local/webserver/nginx/logs/logs/nginx_error.log crit;
pid /usr/local/webserver/ nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events {
use epoll;
worker_connections 51200;
}

metypes in {

me.type in ;

default_type application/octet-strim;
charset utf-8;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_🎜>large_client_client _saiz 8m;

hantar fail dihidupkan;
tcp_nopush dihidupkan;
keepalive_timeout 60;
tcp_nodelay dihidupkan;

fastcgi_connect_timeout 300;
fastcgi_out_timeout 300;

fastcgi_out_time;

fastcgi_buffer_saiz 64k ;
fastcgi_buffers 8 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;

gzip on;
gzip on

4 16k;

gzip_http_versi 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>#百箜丸,站点文件夹必须放在nginx的html目录,否则不支持多站点
pelayan {

dengar 80;

v-cal.webr.name>;/🎜>v-server.weblo.com> /nginx/html/www.v-ec.com;
index index.php index.html;

lokasi ~ .*.(php|php5)?$ {
#fastcgi_pass unix: /tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;

serta fcgi.conf;

}

lokasi ~ .*. (gif|jpg|jpeg|png|bmp|swf)$ {
tamat tempoh 30h;
}

lokasi ~ .*.(js|css)?$ {
tamat 6j;
}

log_format veclog '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_for_for ';
access_log logs/vec.log veclog;

}

#多个站点设置,站点文件夹必须放在nginx的html目录,亙点设置,站点文件夹必须放在nginx的html目录,亙点文件夹必须放在nginx的html目录,亙点文件夹必须放在nginx。 >pelayan {
dengar 80;
nama_pelayan www.w3cgroup.com;
root /usr/local/webserver/nginx/html/www.w3cgroup.com;
index index.php index.html;

lokasi ~ .*.(php|php5)?$ {
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
serta fcgi.conf;

}


lokasi ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
tamat tempoh 30h;
}

lokasi ~ .*.(js|css)?$ {
tamat tempoh 6j;
}

format_log w3cclog '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" $http_x_forwarded_for';
access_log logs/w3c.log w3clog;
}

}



九、配置开机自动启动nginx + php


vi /etc/rc.local

在末尾增加以下: 1 /usr/local/webserver/php/sbin/php-fpm start/usr/local/webserver/nginx/sbin/nginx

十、优化linux内核

vi /etc/sysctl.conf

在末尾增加以下内容:

net.ipv4.tcp_fin_timeout = 30.0.net
net.ipv4.tcp_syncookies = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_tw_recycle = 1

使配置

做到这里,可以reboot重启linux了,不出意外的话应该可以顺利开
ps aux | grep nginx
找到nginx的master process,假如为:5800,然后kill
kill –hup 5800
平滑重启phpphp-fpm的其他命令:mula | berhenti | berhenti | mulakan semula | muat semula | logrotate

Atas ialah kandungan terperinci Bagaimana untuk menyediakan pelayan WEB berprestasi tinggi dengan Linux+Nginx+Php. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Artikel ini dikembalikan pada:yisu.com. Jika ada pelanggaran, sila hubungi admin@php.cn Padam