nginx ("engine x") est un serveur proxy http et inverse hautes performances, ainsi qu'un serveur proxy imap/pop3/smtp. nginx a été développé par igor sysoev pour rambler.ru, le deuxième site le plus visité en Russie, où il fonctionne depuis plus de deux ans et demi. igor publie le code source sous une licence de type BSD. Bien qu'encore en version bêta, nginx est déjà connu pour sa stabilité, son riche ensemble de fonctionnalités, ses exemples de fichiers de configuration et sa faible consommation de ressources système.
1. Compilez et installez les bibliothèques de support requises pour 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. Compilez et installez la bibliothèque d'extension 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/
./configure --prefix=/usr/local/webserver/mysql/ --enable-assembler --with -extra-charsets=complexe --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile - -with- plugins=innobase
make && make install
chmod +w /usr/local/webserver/mysql
chown -r mysql:mysql /usr/local/webserver/mysql
cd ../
l'installation de mysql est omise ici
3. Compilez et installez php (mode 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-discard-path - -enable -safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi -- activer- 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. Modifiez le fichier de configuration php-fpm
rm -f /usr/local/webserver/php/etc/php-fpm.conf
vi /usr/local/webserver/php /etc/ php-fpm.conf
Entrez le contenu suivant :
< nom de la valeur="emergency_restart_interval">1m
< valeur nom="utilisateur">www
# 🎜🎜#五、创建www用户组及www用户
/usr/sbin/groupadd www/usr/sbin/useradd -g www www
# 🎜🎜#
六、编译安装nginx
tar zxvf nginx-0.6.35.tar.gzcd nginx-0.6.35/ 默认安装:
make && make install
默认情况下,nginx 安装在 /usr/local/nginx。译选项,你可以改变这个设定。
指定编译选项安装,如:
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx - -with-http_stub_status_module --with-http_ssl_module
make && make install
七、创建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 request_method $request_method;
fast cgi_param content_type $content_type;# 🎜🎜#fastcgi_param content_length $content_length;
fastcgi_param script_name $fastcgi_script_name;
fastcgi_param request_uri $request_uri;# 🎜🎜#fastcgi_param document_uri $document_uri;
fastcgi_param document_root $document_root;
fastcgi_param server_protocol $server_protocol;
fastcgi_param remote_addr $remote_addr;
fastcgi_param server_name $server_name;
# php uniquement, requis si php a été construit avec --enable-force-cgi-redirect
fastcgi_param redirect_status 200;
八、编辑nginx配置文件
rm -f /usr/local/webserver/nginx/conf/ nginx.confvi /usr/local/webserver/nginx/conf/nginx.conf
user www www;
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;
}
http {
include mime.types;#🎜 🎜 #default_type application/octet-stream ; 🎜🎜#client_max_body_size 8m;
tcp_nopush le;
keepalive_timeout 60;
tcp_nodelay le;
fastcgi_connect_timeout 300;#🎜 🎜#fastcgi_send_timeout 300 ;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 8 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip dessus;#🎜🎜 #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 www.v-ec.com;
root /usr/local/webserver/nginx/html/www.v-ec.com;
index index .php index.html;
location ~ .*.(php|php5)?$ {
fastcgi_pass 127.0 .0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*.(gif|jpg|jpeg|png| bmp|swf)$ {
expire 30j;
location ~ .*.(js|css)?$ {
expire 6h;
}
log_format veclog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
access_log logs/vec.log veclog;
}
#多个站点设置,站点文件夹必须放在nginx的html目录,否则不支持多站点
serveur {
listen 80;
server_name www.w3cgroup.com;
root /usr/local/webserver/nginx/html/www.w3cgroup.com;
index index.php index.html;
emplacement ~ .*.(php|php5)?$ {
fastcgi_pass 127.0.0.1 :9000;
fastcgi_index index.php;
include fcgi.conf;
location ~ .*.(gif|jpg|jpeg|png|bmp| swf)$ {
expire 30j;
}
location ~ .*.(js|css)?$ {
expire 6h;
}# 🎜🎜#
log_format w3cclog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for' ;
}
}
九、配置开机自动启动nginx + php
#🎜 🎜#
vi /etc/rc.local
在末尾增加以下内容:
/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#🎜 🎜#net. ipv4.tcp_keepalive_time = 300net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_tw_recycle = 1
使配置立即生效:
/sbin/sysctl –p
平滑重启nginx
找到nginx的master process,假如为:5800,然后kill
kill –hup 5800平滑重启php#🎜🎜 #/usr/local /webserver/php/sbin/php-fpm restart
php-fpm的其他命令:start | arrêter | quitter | redémarrer | recharger | logrotate
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!