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模式)
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設定檔
vi /usr/local/webserver/php/etc/php-fpm.conf
##輸入以下內容:
/ usr /local/webserver/php/logs/php-fpm.pid
通知值>
10值>
1m值>
5s值>
是值>
-1值>
值>
值>
0666值>
/usr/sbin/sendmail -t -i值>
1值>
值>
www值>
www
靜態值>
128< ;/值>
20值>
5
35值>
值>
值>
0s值>
0s值>
logs/slow.log值>
51200值>
0值>
值>
值>
是值>
500
$hostname
/tmp值>
/tmp值>
##五、建立www用戶群組及www用戶
##/usr/sbin/groupadd www
#/ usr/sbin/useradd -g www www
#六、編譯安裝nginx
#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 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
fastcgi_param redirect_status 200;
#八、編輯nginx設定檔
rm -f /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;
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;
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;
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;
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;
}
#.位置~ .* \.(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目錄下,否則不支援多網站
listen 80;
server_name www.w3cgroup.com;
root /usr/local/webserver/nginx/html/www.w3cgroup.com;
位置~ .*\.(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;## }
}
##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 = 30net. ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
>生效:
/sbin/sysctl –p
做到這裡,可以重啟重啟linux了,不出意外的話應該可以順利開啟nginx
#平滑重啟nginx
ps 輔助 | grep nginx
找到nginx的主程序,假設為:5800,然後kill
kill –hup 5800
以上是Linux+Nginx+Php如何架設高效能WEB伺服器的詳細內容。更多資訊請關注PHP中文網其他相關文章!

NGINX和Apache各有優劣,適合不同場景。 1.NGINX適合高並發和低資源消耗場景。 2.Apache適合需要復雜配置和豐富模塊的場景。通過比較它們的核心特性、性能差異和最佳實踐,可以幫助你選擇最適合需求的服務器軟件。

確認 Nginx 是否啟動的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 檢查端口 80 是否開放;3. 查看系統日誌中 Nginx 啟動消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

要關閉 Nginx 服務,請按以下步驟操作:確定安裝類型:Red Hat/CentOS(systemctl status nginx)或 Debian/Ubuntu(service nginx status)停止服務:Red Hat/CentOS(systemctl stop nginx)或 Debian/Ubuntu(service nginx stop)禁用自動啟動(可選):Red Hat/CentOS(systemctl disable nginx)或 Debian/Ubuntu(syst

如何在 Windows 中配置 Nginx?安裝 Nginx 並創建虛擬主機配置。修改主配置文件並包含虛擬主機配置。啟動或重新加載 Nginx。測試配置並查看網站。選擇性啟用 SSL 並配置 SSL 證書。選擇性設置防火牆允許 80 和 443 端口流量。

服務器無權訪問所請求的資源,導致 nginx 403 錯誤。解決方法包括:檢查文件權限。檢查 .htaccess 配置。檢查 nginx 配置。配置 SELinux 權限。檢查防火牆規則。排除其他原因,如瀏覽器問題、服務器故障或其他可能的錯誤。

在 Linux 中啟動 Nginx 的步驟:檢查 Nginx 是否已安裝。使用 systemctl start nginx 啟動 Nginx 服務。使用 systemctl enable nginx 啟用在系統啟動時自動啟動 Nginx。使用 systemctl status nginx 驗證啟動是否成功。在 Web 瀏覽器中訪問 http://localhost 查看默認歡迎頁面。

在 Linux 中,使用以下命令檢查 Nginx 是否已啟動:systemctl status nginx根據命令輸出進行判斷:如果顯示 "Active: active (running)",則 Nginx 已啟動。如果顯示 "Active: inactive (dead)",則 Nginx 已停止。


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Atom編輯器mac版下載
最受歡迎的的開源編輯器

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。