nginx實例配置過程:
直接從網路上下載rpm安裝包:nginx-0.6.39-4.el4.i386.rpm
直接安裝 rpm -ivh nginx-0.6.39-4.el4.i386.rpm 在RHEL4.0可以直接安裝,無需其他安裝包依賴
然後是配置/etc/nginx/nginx.conf
具體配置內容:
user www www; #用戶 用戶組
worker_processes 2; #這裡根據CPU個數設置,但是可以實際的多一些
error_log /var/log/nginx/error.log; #這個是日誌的位置
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid; #這個默認就可以
events {
worker_connections 2048; #可以設置稍微大一些 1024的倍數
}
http {
include /etc/nginx/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 /var/log/nginx/logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8080; #這裡是監聽埠
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /var/www/html/; #這裡是網站伺服器的根目錄,記得如果測試,請在該目錄下面touch index.html 生成一個index.html 文件
index index.html index.htm;
}
#error_page 404 /404.html;
# 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$ { #這裡是通過fastcgi來為NGINX開始php服務功能
root /var/www/html/; #設置目錄
fastcgi_pass 127.0.0.1:9000; #設置監聽埠
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# 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;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4 RSA: HIGH: MEDIUM: LOW: SSLv2: EXP;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
光是安裝nginx無法使用php 需要配置/etc/nginx/nginx.conf 其實就是把相應欄位的#號去掉.
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ { #這裡是通過fastcgi來為NGINX開始php服務功能
root /var/www/html/; #設置目錄 這個設置完成後,打開IE http://192.168.133.128,默認會查找/var/www/html/index.php這個文件
fastcgi_pass 127.0.0.1:9000; #設置監聽埠
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
還需要安裝軟體spawn-fcgi-1.6.3-1.el4.i386.rpm,這個文件算是lighttp下面的一個,主要用來啟動php-cgi
還需要php安裝是cgi模式,這樣會生成php-cgi文件
我直接使用rhel4.0,裡面默認安裝的是PHP4.0,並沒有php-cgi文件(直接安裝php-cli-5.3.6-3.el4.remi.i386.rpm文件好像也不可行)
因此直接刪除php4.0 安裝PHP 5.3.6 (cli) (built: Apr 15 2011 20:47:07)
具體刪除php4.0就不細說了,查看安裝的php相關文件 rpm -qa|grep php ,然後刪除所有相關文件
下載php5.3.6相關文件,列表如下:
-rw-r--r-- 1 root root 1282958 Mar 8 16:11 mysql-libs-5.5.11-1.el4.remi.i386.rpm
-rw-r--r-- 1 root root 2020731 Mar 8 16:11 MySQL-shared-5.5.11-1.rhel4.i386.rpm
-rw-r--r-- 1 root root 1350089 Mar 8 15:54 php-5.3.6-3.el4.remi.i386.rpm
配置Nginx 配置虛擬主機
vi /etc/nginx/nginx.conf
具體配置如下:請把相關行的#去掉
# another virtual host using mix of IP-, name-, and port-based configuration
問題1:
打開IE,直接輸入地址***.php: 屏幕顯示 No input file specified
解決方案:
方法1php.ini的配置中
將這條cgi.fix_pathinfo=1前面的;去掉 后再重啟php-cgi,php顯示正常
記得修改了php.ini要重啟fastcgi服務. 我這裡單修改這個,還是不成,又用了方法2,才OK.
方法2
nginx中的配置有些麻煩
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
每個虛機要根據自己不通的虛機設置不能的目錄,要保證這個路徑正確.
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;不能在fastcgi_pass 127.0.0.1:9000;的前面.
打開:http://192.168.133.128:8080/index.php
顯示如下:this is php web test one !!!!!
問題2:
spawn-fcgi -a 127.0.0.1 -p 9000 -u www -f /usr/bin/php-cgi 使用這條命令提示如下:
spawn-fcgi: child exited with: 126 當時使用PHP4.0 ,系統中沒有php-cgi這個文件
spawn-fcgi: child exited with: 13 使用PHP5.3.6 ,命令中多了-C 64 出錯
spawn-fcgi: child exited with: 2 使用PHP5.3.6 ,命令中多了-C 64 出錯
本文出自 「wxfxn2000」 博客,謝絕轉載!
[火星人 ] linux nginx 配置以及排錯已經有523次圍觀