中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Linux+Nginx+Php如何架設高性能WEB服務器

發布時間:2022-03-24 15:54:07 來源:億速云 閱讀:156 作者:iii 欄目:web開發

本篇內容主要講解“Linux+Nginx+Php如何架設高性能WEB服務器”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Linux+Nginx+Php如何架設高性能WEB服務器”吧!

nginx ("engine x") 是一個高性能的 http 和 反向代理 服務器,也是一個 imap/pop3/smtp 代理服務器 。 nginx 是由 igor sysoev 為俄羅斯訪問量第二的 rambler.ru 站點開發的,它已經在該站點運行超過兩年半了。igor 將源代碼以類bsd許可證的形式發布。盡管還是測試版,但是,nginx 已經因為它的穩定性、豐富的功能集、示例配置文件和低系統資源的消耗而聞名了。

安裝步驟

一、 編譯安裝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擴展庫

/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

輸入以下內容:

<?xml version="1.0" ?>
<configuration>
<section name="global_options">
<value name="pid_file">/usr/local/webserver/php/logs/php-fpm.pid</value>
<value name="error_log">/usr/local/webserver/php/logs/php-fpm.log</value>
<value name="log_level">notice</value>
<value name="emergency_restart_threshold">10</value>
<value name="emergency_restart_interval">1m</value>
<value name="process_control_timeout">5s</value>
<value name="daemonize">yes</value>
</section>
<workers>
<section name="pool">
<value name="name">default</value>
<value name="listen_address">127.0.0.1:9000</value>
<value name="listen_options">
<value name="backlog">-1</value>
<value name="owner"></value>
<value name="group"></value>
<value name="mode">0666</value>
</value>
<value name="php_defines">
<value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
<value name="display_errors">1</value>
</value>
<value name="user">www</value>
<value name="group">www</value>
<value name="pm">
<value name="style">static</value>
<value name="max_children">128</value>
<value name="apache_like">
<value name="startservers">20</value>
<value name="minspareservers">5</value>
<value name="maxspareservers">35</value>
</value>
</value>
<value name="request_terminate_timeout">0s</value>
<value name="request_slowlog_timeout">0s</value>
<value name="slowlog">logs/slow.log</value>
<value name="rlimit_files">51200</value>
<value name="rlimit_core">0</value>
<value name="chroot"></value>
<value name="chdir"></value>
<value name="catch_workers_output">yes</value>
<value name="max_requests">500</value>
<value name="allowed_clients">127.0.0.1</value>
<value name="environment">
<value name="hostname">$hostname</value>
<value name="path">/usr/local/bin:/usr/bin:/bin</value>
<value name="tmp">/tmp</value>
<value name="tmpdir">/tmp</value>
<value name="temp">/tmp</value>
<value name="ostype">$ostype</value>
<value name="machtype">$machtype</value>
<value name="malloc_check_">2</value>
</value>
</section>
</workers>
</configuration>

五、創建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/
默認安裝:
./configure
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
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 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

輸入以下內容:

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;
#多個站點設置,站點文件夾必須放在nginx的html目錄,否則不支持多站點
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;
}
#多個站點設置,站點文件夾必須放在nginx的html目錄,否則不支持多站點
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;
}
}

九、配置開機自動啟動nginx + php

vi /etc/rc.local

在末尾增加以下內容:

ulimit -shn 51200
/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 = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1

使配置立即生效:

/sbin/sysctl –p

做到這里,可以reboot重啟linux了,不出意外的話應該可以順利開啟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

到此,相信大家對“Linux+Nginx+Php如何架設高性能WEB服務器”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

乐平市| 普安县| 桦南县| 永平县| 玉田县| 台中县| 富平县| 陆丰市| 韩城市| 呼玛县| 普兰县| 罗山县| 视频| 和平县| 宣化县| 贡山| 宁化县| 黔西县| 庆城县| 肥乡县| 辽源市| 庐江县| 上饶市| 绥宁县| 鱼台县| 灵石县| 麟游县| 海口市| 普安县| 临湘市| 昌图县| 宁武县| 石嘴山市| 大荔县| 虞城县| 芜湖县| 石林| 西林县| 洪洞县| 德江县| 泗阳县|