os環境:centos 6.1
nginx:nginx-1.2.2
php:php5.3.14
0、安裝依賴套件
複製程式碼 程式碼如下:
yum install openssl-devel pcre-devel zlib-devel libjpeg-devel libpng-devel freetype-devel gcc make
1、新增www 使用者用來執行nginx
#複製程式碼 程式碼如下:
useradd -m -r -s /sbin/nologin -d /opt/web/ www
2、建立臨時目錄
#複製程式碼 程式碼如下:
mkdir -p /var/tmp/nginx/client/
mkdir -p /var/tmp/nginx/proxy/
mkdir -p /var/tmp/nginx /fcgi/
3、下載nginx最新穩定版原始碼
複製程式碼 程式碼如下:
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.2.2.tar.gz
4、解壓縮,編譯,安裝
##複製程式碼 程式碼如下:
tar vxzf nginx-1.2.2.tar.gz
cd nginx-1.2.2/
./configure \
--prefix=/opt/web/nginx \
--error -log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/ nginx.lock \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
- -http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi -temp-path=/var/tmp/nginx/uwsgi/
make
make install
5、設定nginx
複製程式碼 程式碼如下:
vim /opt/web/nginx/conf/nginx.conf
# 指定啟動用戶:
user www www;
# 進程數量,nginx作者認為一個就可以,根據自己的訪問量修改
worker_processes 1;
# 設定錯誤日誌:
#error_log logs/error.log notice;
#error_log logs/error.log info;
error_log /var/log/nginx/ error.default.log;
pid /opt/web/nginx/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
charset utf-8;
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$ status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip. application/x-javascript application/xml
application/atom xml text/javascript;
server {
listen 80;
server_name localhost;
charset utf-8;
#access_log logs /host.access.log main;
location / {
index index.html index.htm;
}
## redirect server error pages to the static page /50x.html
#error_page 500 502 503 504 /50x.html;
location = /50x.html {###root html;### ### proxy the php scripts to apache listening on 127.0.0.1:80########location ~ \.php$ {#### proxy_pass http://127.0.0.1;#####}# ### pass the php scripts to fastcgi server listening on 127.0.0.1:9000#######location ~ \.php$ {####root html;###fastcgi_pass 127.0.0.1:9000;### fastcgi_index index.php;####fastcgi_param script_filename /scripts$fastcgi_script_name;####include fastcgi_params;###include fastcgi.conf;###}##### denyaccess to .htroot aches, docifum #### concurs with nginx's one#######location ~ /\.ht {###deny all;###}###}#### another virtual host using mix of ip-, name -, and port-based configuration########server {#### listen 8000;#### listen somename:8080;#### server_name somename alias another.alias;##### location / {#### root html;#### index index.html index.htm;#### }####}#### https server#######server {#### listen 443;#### server_name localhost;#### ssl on;#### ssl_certificate cert.pem;#### ssl_certificate_key cert.key;#### ssl_session_timeout 5m;ss#ftls. ;#### ssl_ciphers high:!anull:!md5;#### ssl_prefer_server_ciphers on;#### location / {#### root html;##### index index.html index.htm;################ index.htm;#### # }####}###proxy_read_timeout 200;#### only retry if there was a communication error, not a timeout#### on the tornado server (to avoid propagating "queries of death"###. to all frontends)###proxy_next_upstream error;###proxy_set_header x-scheme $scheme;###proxy_set_header x-real-ip $remote_addr;###proxy_set_header host $host;##profprod-#pronxy proxy_add_x_forwarded_for;#### 引入虛擬主機檔案###include /opt/web/nginx/conf/sites/*.conf;###}#######6、建立虛擬機器設定檔存放的目錄# ########複製程式碼 程式碼如下:######mkdir /opt/web/nginx/conf/sites###這樣配置後,需要新增加虛擬主機的直接在nginx/conf/sites/目錄下,新增設定檔即可
例如:現在有www.jb51.net 網域
建立:/opt/ web/nginx/conf/sites/www.jb51.net.conf 檔案
內容如下:
複製程式碼 程式碼如下:
server {
listen 80;
client_max_body_size 10m;
#多個網域以空格分割,第一個為預設
server_name www.jb51.net jb51.net;
charset utf-8;
index index.html index.htm index.php;
# 定義根目錄
set $root /var/webroot/www.jb51.net/;
# 設定網站路徑
root $root;
#防止目錄瀏覽
autoindex off;
if ($host != 'www.jb51.net') {
rewrite ^/(.*)$ //www.jb51.net/$1 permanent;
}
# 防止.htaccess檔案被要求
location ~ /\.ht {
deny all;
}
error_page 404 /404.html;
index index.html index.htm;
location /uploads/ {
alias /data/webroot/www.jb51.net/uploads/;
}
try_files $uri @uwsgi;
location @uwsgi{
# 將其它的請求轉交給uwsgi
include uwsgi_params;
uwsgi_pass unix:/tmp/360ito_uwsgi.sock;
proxy_set_header x-real-iphostremote_addr;
##如果 好吧 好吧 好吧D 她 她 她 她 她 hostr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
#proxy_pass http://localhost:5000;
}
## 將php類型的請求轉交給fastcgi
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
## 存取日誌:
access_log /var /log/nginx/access.www.jb51.net.log;
# 載入.htaccess重寫文件,注意,這裡不支援變數路徑
# include /var/webroot/www.jb51.net/.htaccess;
# 開啟網域跳轉,則當存取出錯後,其他網域會自動跳到www.jb51.net
server_name_in_redirect on;
}
7、安裝最新版本php( php5.3.14 )
#cd /usr /local/src/
tar xjvf php-5.3.14.tar.bz2
cd php-5.3.14執行:
如果報錯,可能是你的autoconf不是2.13 版本的,php5.3.系列的bug,需要安裝autoconf為2.13的版本:
複製程式碼 程式碼如下:
centos : # yum install autoconf213
debian : # apt-get install autoconf2.13
設定環境變數
##複製程式碼 程式碼如下:
## centos :
#export php_autoconf="/usr/bin/autoconf-2.13"
# debian :
export php_autoconf="/usr/bin/autoconf2.13"
#再運作:./buildconf - -force ,出現buildconf: autoconf version 2.13 (ok)
,則表示成功。編譯安裝php
複製程式碼 程式碼如下:
./configure \
--prefix=/opt/web/php \
--with -config-file-path=/opt/web/php/etc \
--with-config-file-scan-dir=/opt/web/php/etc/conf.d \
--enable -fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=/opt/db/percona-server-5.5.14 -rel20.5 \
--with-mysqli=/opt/db/percona-server-5.5.14-rel20.5/bin/mysql_config \
--with-iconv-dir \
- -with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--enable-mbstring \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
make && make install
cp php.ini-production /opt/web/php/etc/php.ini
cp php-fpm.conf.default php-fpm.conf
#修改php-fpm.conf 啟用如下幾行,也就是去掉前面的分號(;)
複製程式碼 程式碼如下:
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
#user = www
group = www
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
#pm.max_requests = 500
#env[path] = /usr/local/bin:/usr/bin:/bin
env[tmp] = /tmp
env[temp] = / tmp
8、啟動php-fpm
複製程式 程式碼如下:
/opt/web/php/sbin/php-fpm
10、在瀏覽器網址列輸入:http://php.jb51.net/tz.php
成功的話,可以看到phpinfo()輸出的資訊
以上是CentOS環境中怎麼部署nginx、php和虛擬主機的詳細內容。更多資訊請關注PHP中文網其他相關文章!

NGINX可用於提升網站性能、安全性和可擴展性。 1)作為反向代理和負載均衡器,NGINX可優化後端服務和分擔流量。 2)通過事件驅動和異步架構,NGINX高效處理高並發連接。 3)配置文件允許靈活定義規則,如靜態文件服務和負載均衡。 4)優化建議包括啟用Gzip壓縮、使用緩存和調整worker進程。

NGINXUnit支持多種編程語言,通過模塊化設計實現。 1.加載語言模塊:根據配置文件加載相應模塊。 2.應用啟動:調用語言運行時執行應用代碼。 3.請求處理:將請求轉發給應用實例。 4.響應返回:將處理後的響應返回給客戶端。

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 權限。檢查防火牆規則。排除其他原因,如瀏覽器問題、服務器故障或其他可能的錯誤。


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

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

禪工作室 13.0.1
強大的PHP整合開發環境

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

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境