Nginx Web Server 設定檔
# rpm -qc nginx
/etc/logrotate.d/nginx
/etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/example_ssl.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
[@more@]設定 Nginx Web Server
# vim /etc/nginx/nginx.conf
# 啟動 Nginx 的使用者
user nginx;
worker_processes 1;
# Nginx Web Server Error Log 位置和記錄的層級
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
# 連線數量
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# log 檔記錄的格式
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/access.log main;
sendfile on;
#tcp_nopush on;
# 保持連線的 timeout 時間
keepalive_timeout 65;
#gzip on;
# 其它的設定檔在 /etc/nginx/conf.d 目錄之下
include /etc/nginx/conf.d/*.conf;
}
修改 /etc/nginx/conf.d/default.conf 設定檔
# vim /etc/nginx/conf.d/default.conf
# 開啟的連線埠和主機名稱
server {
listen 80;
server_name localhost;
# 編碼設定
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
# 網頁根目錄 /usr/share/nginx/html 和預設首頁的檔案名稱
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# 發生找不到檔案 404 錯誤編碼時,可以導引至
#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 /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}
# 開啟 PHP 功能
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 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;
#}
}
安裝 php-fpm 套件
# yum install php-fpm
啟動 php-fpm
# /etc/init.d/php-fpm start
Starting php-fpm: [ OK ]
php-fpm 會使用到 tcp 9000 埠
# netstat -antulp | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3769/php-fpm
設定開機時啟動 php-fpm
# chkconfig –list php-fpm
php-fpm 0:off 1:off 2:off 3:off 4:off 5:off 6:off
# chkconfig –level 3 php-fpm on
重新啟動 Nginx Web Server
# service nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
在防火牆上打開 9000 埠
-A INPUT -m state –state NEW -m tcp -p tcp –dport 9000 -j ACCEPT
測試 PHP 功能
# vim /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
中文字顯示正常