目錄
安裝步驟
首頁 運維 Nginx Linux+Nginx+Php如何架設高效能WEB伺服器

Linux+Nginx+Php如何架設高效能WEB伺服器

May 20, 2023 pm 11:19 PM
php linux nginx

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
##輸入以下內容:


<設定>
<節名稱=“global_options”>
<值名稱=“pid_file”>/ usr /local/webserver/php/logs/php-fpm.pid
/usr/local/webserver/php/logs/php-fpm.log ;
通知值>
10值>
1m
<值名稱=“process_control_timeout”>5s
<值名稱=“daemonize”>是



default
127.0.0.1:9000值>

-1值>














<值名稱=「群組」>
<值名稱=「模式」>0666
< /value>
<值名稱= “php_defines”>
<值名稱=“sendmail_path”>/usr/sbin/sendmail -t -i
<值名稱="display_errors">1

<值名稱=“用戶”>www
<值名稱=“組”> ​​www

<值名稱=“pm”>
<值名稱=“style”>靜態
<值名稱=“max_children”>128< ;/值>
<值名稱=“apache_like”>
<值名稱=“startservers”>20
<值名稱=“minspareservers”>5< /值>
<值名稱=“maxspareservers”>35


<值名稱=“request_terminate_timeout”> 0s
<值名稱=“request_slowlog_timeout”>0s
<值名稱=“slowlog”> logs/slow.log
<值名稱=“rlimit_files”>51200
<值名稱=“rlimit_core”>0
<值名稱=“chroot ”>
<值名稱=“chdir”>
<值名稱=“catch_workers_output”>是
<值名稱=“max_requests”>500< /值>

<值名稱=“allowed_clients”>127.0.0.1

<值名稱=“環境”><值名稱=“主機名稱”> $hostname /usr/local/bin:/usr/bin:/bin

/tmp

<值名稱=“tmpdir”>/tmp
<值名稱=“temp”>/tmp

<值name="ostype">$ostype

$machtype
2

#



##五、建立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 /###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 th ;

fastcgi_param script_filename $document_root$fastcgi_script_name;

fastcgi_param script_name $fastcgi_script_name;

fastcgi_param request_uri $refast_uri;
1_param _param server_protocol $server_protocol;

fastcgi_param remote_addr $remote_addr;
fastcgi_param remote_port $remote_port;
fastcgi_param server_addrserver_addr_#_fast_fastcgi_#fastcgi_param server_addrserver_addr_#_fast_fastcgi_#_fastcgi_para

# 僅適用於php,如果使用--enable-force-cgi-redirect 建構php,則需要

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 {
##http {
include mime.types ;
default_type application/octet-stream;
charset utf-8;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;fclis_clis_s; ;


sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_#fastcgi_connect_timeout 300;
fastcgi_send_時間##fastcgi_buffer_size 64k ;
fastcgi_buffers 8 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;

gzip;

#g #gzip_http_version 1.0;

gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;

#limit_zonecrawler $binary_remoler_addr 100個網站設置,網站資料夾必須放在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;

}



#.位置~ .* \.(gif|jpg|jpeg|png|bmp|swf)$ {
過期30d;
}

位置~ .*\.(js|css)?$ {
過期6 小時;
}

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;


位置~ .*\.(php|php5)?$ {
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index 索引。php;
include fcgi.conf;
}

位置~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
過期30 天;
}

位置~ .*\.(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 日誌/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

做到這裡,可以重啟重啟linux了,不出意外的話應該可以順利開啟nginx

#平滑重啟nginx


ps 輔助 | grep nginx
找到nginx的主程序,假設為:5800,然後kill
kill –hup 5800

平滑重啟php

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

php-fpm的其他指令:start |停止|退出 |重啟|重新加載 |對數旋轉

以上是Linux+Nginx+Php如何架設高效能WEB伺服器的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
4 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

nginx運行一段時間就掛掉怎麼回事 nginx運行一段時間就掛掉怎麼回事 Apr 14, 2025 am 07:18 AM

nginx 運行一段時間後掛掉的原因:1. 內存洩漏;2. 配置錯誤;3. 資源不足;4. 外部因素。解決方法:1. 診斷內存洩漏;2. 修復配置錯誤;3. 提供更多資源;4. 排除外部因素。

nginx負載均衡如何實現 nginx負載均衡如何實現 Apr 14, 2025 am 07:21 AM

Nginx 負載均衡通過 upstream 模塊定義後端服務器,並使用 location 塊將請求代理到這些服務器。支持輪詢、最少連接數、響應時間加權和 ip_hash 等負載均衡策略。配置示例包括定義 upstream 組和使用 proxy_pass 指令指向它。

nginx重新啟動的命令 nginx重新啟動的命令 Apr 14, 2025 am 07:27 AM

nginx 重新啟動命令:sudo systemctl restart nginx。其他相關命令包括:1.啟動:sudo systemctl start nginx;2.停止:sudo systemctl stop nginx;3.檢查狀態:sudo systemctl status nginx。

nginx autoindex是什麼意思 nginx autoindex是什麼意思 Apr 14, 2025 am 07:36 AM

Nginx Autoindex 是一種生成目錄列表 HTML 頁面的功能,用於在請求目錄而非文件時瀏覽文件、查看文件信息。它可通過配置選項定制,如顯示確切文件大小、本地時間和自定義頁面格式。優點包括方便瀏覽、易於配置和提供文件信息。缺點包括安全風險、性能影響和無法自定義頁面外觀。

nginx403什麼原因 nginx403什麼原因 Apr 14, 2025 am 07:39 AM

nginx 403 錯誤表示客戶端無權訪問資源。造成此問題的因素可能包括:權限設置、nginx 配置、CGI 腳本錯誤、.htaccess 文件或其他原因。排查步驟包括:檢查權限設置、審查 nginx 配置、測試 CGI 腳本、檢查 .htaccess 文件、排除防火牆或安全軟件,以及檢查服務器和文件系統。

nginx如何配置虛擬主機 nginx如何配置虛擬主機 Apr 14, 2025 am 08:15 AM

配置 nginx 虛擬主機允許在一個服務器上託管多個網站,每個網站擁有獨立域名和根目錄。具體配置步驟包括:創建虛擬主機配置文件配置服務器塊,指定服務器監聽端口、虛擬主機域名和文檔根目錄啟用虛擬主機,將配置文件鏈接到啟用目錄重新加載 nginx

nginx中如何重定向 nginx中如何重定向 Apr 14, 2025 am 08:42 AM

通過 Nginx 進行重定向的方法有 301 永久重定向(更新鏈接或移動頁面)和 302 臨時重定向(處理錯誤或臨時更改)。配置重定向涉及在 server 塊中使用 location 指令,高級功能包括正則表達式匹配、代理重定向和基於條件的重定向。重定向的常見用途包括更新 URL、處理錯誤、將 HTTP 重定向到 HTTPS,以及引導用戶訪問特定國家或語言版本。

nginx和web服務器的關係 nginx和web服務器的關係 Apr 14, 2025 am 07:09 AM

nginx 是一個輕量級、非阻塞的 Web 服務器和反向代理,常用於前端代理、負載平衡和緩存。它與 Web 服務器的關係通常是:前端代理:nginx 處理請求並轉發到後端服務器。負載平衡器:nginx 將請求分發到多台後端服務器。緩存:nginx 緩存經常訪問的文件以提高性能。

See all articles