成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Linux+Nginx+Php架設(shè)高性能WEB服務(wù)器

2022-10-09    分類: 網(wǎng)站建設(shè)

Nginx ("engine x") 是一個(gè)高性能的 HTTP 和 反向代理 服務(wù)器,也是一個(gè) IMAP/POP3/SMTP 代理服務(wù)器 。 Nginx 是由 Igor Sysoev 為俄羅斯訪問量第二的 Rambler.ru 站點(diǎn)開發(fā)的,它已經(jīng)在該站點(diǎn)運(yùn)行超過兩年半了。Igor 將源代碼以類BSD許可證的形式發(fā)布。盡管還是測試版,但是,Nginx 已經(jīng)因?yàn)樗姆€(wěn)定性、豐富的功能集、示例配置文件和低系統(tǒng)資源的消耗而聞名了。

本文是W3CGROUP在成功架設(shè)Nginx+Php Web服務(wù)器之后的一個(gè)總結(jié),成功設(shè)置Nginx開啟多域名多站點(diǎn),并且不會出現(xiàn)502 Bad Gateway錯(cuò)誤!

本文測試環(huán)境如下:

系統(tǒng)環(huán)境

Linux version 2.6.9(CentOS release 4.7(Final))

軟件環(huán)境

nginx-0.6.35.tar.gz
當(dāng)前穩(wěn)定版: Nginx 0.6.35 (2009年1月26日)
官方Wiki:http://wiki.nginx.org
官方下載:http://sysoev.ru/nginx/nginx-0.6.35.tar.gz

php-5.2.9.tar.gz
官方下載:http://www.php.net/get/php-5.2.9.tar.gz/from/this/mirror

php-5.2.9-fpm-0.5.10.diff.gz
官方下載:http://php-fpm.anight.org/downloads/archive/

mysql-5.1.34.tar.gz

libiconv-1.13.tar.gz

libmcrypt-2.5.8.tar.gz

mcrypt-2.6.8.tar.gz

mhash-0.9.9.9.tar.gz

 

Nginx0.6.35+Php5.2.9所有相關(guān)安裝包下載 http://www.w3cgroup.com/code/nginx_php.rar


安裝步驟

一、 編譯安裝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 ../

二、編譯安裝MySQL 5.1.34擴(kuò)展庫

/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=complex --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 ../

MySql的安裝此處就省略

三、編譯安裝PHP(FastCGI模式)

tar zxvf php-5.2.9.tar.gz
gzip -cd php-5.2.9-fpm-0.5.10.diff.gz | patch -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 --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 ../

四、修改php-fpm配置文件

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

輸入以下內(nèi)容:




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



default
127.0.0.1:9000

-1


0666


/usr/sbin/sendmail -t -i
1

www
www

static
128

20
5
35


0s
0s
logs/slow.log
51200
0


yes
500
127.0.0.1

$HOSTNAME
/usr/local/bin:/usr/bin:/bin
/tmp
/tmp
/tmp
$OSTYPE
$MACHTYPE
2



五、創(chuàng)建www用戶組及www用戶

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

六、編譯安裝Nginx

tar zxvf nginx-0.6.35.tar.gz
cd nginx-0.6.35/
默認(rèn)安裝:
./configure
make && make install
默認(rèn)情況下,Nginx 會被安裝在 /usr/local/nginx。通過設(shè)定編譯選項(xiàng),你可以改變這個(gè)設(shè)定。

指定編譯選項(xiàng)安裝,如:
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../

七、創(chuàng)建fcgi.conf文件

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

輸入以下內(nèi)容:

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
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 REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --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

輸入以下內(nèi)容:

user 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;
}

http {
include mime.types;
default_type application/octet-stream;
charset utf-8;

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 8 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;

#limit_zone crawler $binary_remote_addr 10m;
#多個(gè)站點(diǎn)設(shè)置,站點(diǎn)文件夾必須放在Nginx的html目錄,否則不支持多站點(diǎn)
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 unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}

location ~ .*.(js|css)?$ {
expires 6h;
}

log_format veclog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log logs/vec.log veclog;
}
#多個(gè)站點(diǎn)設(shè)置,站點(diǎn)文件夾必須放在Nginx的html目錄,否則不支持多站點(diǎn)
server {
listen 80;
server_name www.w3cgroup.com;
root /usr/local/webserver/nginx/html/www.w3cgroup.com;
index index.php index.html;

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

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}

location ~ .*.(js|css)?$ {
expires 6h;
}

log_format 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;
}
}

九、配置開機(jī)自動啟動Nginx + PHP

vi /etc/rc.local

在末尾增加以下內(nèi)容:

ulimit -SHn 51200
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx

十、優(yōu)化Linux內(nèi)核參數(shù)

vi /etc/sysctl.conf

在末尾增加以下內(nèi)容:

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

使配置立即生效:

/sbin/sysctl –p

做到這里,可以reboot重啟Linux了,不出意外的話應(yīng)該可以順利開啟Nginx

平滑重啟Nginx

Ps aux | grep nginx
找到Nginx的master process,假如為:5800,然后kill
Kill –HUP 5800

平滑重啟Php

/usr/local/webserver/php/sbin/php-fpm restart

php-fpm的其他命令:start | stop | quit | restart | reload | logrotate

分享標(biāo)題:Linux+Nginx+Php架設(shè)高性能WEB服務(wù)器
文章網(wǎng)址:http://jinyejixie.com/news/203995.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號云服務(wù)器、自適應(yīng)網(wǎng)站、企業(yè)網(wǎng)站制作、靜態(tài)網(wǎng)站、手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)
枝江市| 报价| 鄢陵县| 双辽市| 林州市| 文山县| 新和县| 中宁县| 兴和县| 佛教| 澜沧| 建湖县| 台南县| 手游| 马山县| 嘉鱼县| 樟树市| 汶上县| 建昌县| 平南县| 故城县| 托里县| 徐州市| 墨脱县| 博野县| 遂宁市| 司法| 奈曼旗| 陆川县| 湄潭县| 娱乐| 漠河县| 金寨县| 宣城市| 保康县| 常州市| 郸城县| 睢宁县| 榆树市| 宜君县| 梧州市|