11. 06.

(8)安装nginx的rewrite模块需要pcre库
# tar zxvf pcre-7.3.tar.gz
# cd pcre-7.3
# ./configure
# make && make install

(9)安装nginx
# ./configure –prefix=/usr/local/nginx –with-http_stub_status_module
# make && make install

(10)编译出lighttpd中附带的spawn-fcgi,它的作用是来启动php-cgi

# tar jxvf lighttpd-1.4.19.tar.bz2
# cd lighttpd-1.4.19
# ./configure
# make
# cp src/spawn-fcgi /usr/local/php-fcgi/bin/

到现在为之, 安装过程已经结束

5.开始配置环境:
# cd /usr/local/nginx/conf
# mkdir vhosts

先备份即将要修改的文件
# cp nginx.conf nginx.conf.bak
# cp fastcgi_params fastcgi_params.bak
# mkdir -p /usr/local/nginx/temp/client_body
# mkdir /usr/local/nginx/var

(1)编辑nginx主配置文件nginx.conf
编辑nginx.conf, 并且把其内容修改为, 最后几行注意自定义一下

daemon on;
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
error_log /dev/null;
pid var/nginx.pid;
lock_file var/nginx.lock;
events {
worker_connections 2048;
use epoll;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_max_size 512;
server_names_hash_bucket_size 128;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 1;
client_header_timeout 10;
client_body_timeout 10;
client_max_body_size 10m;
client_body_buffer_size 256k;
send_timeout 30;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
client_body_temp_path /usr/local/nginx/temp/client_body 1 2;
gzip on;
gzip_min_length 1000;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_comp_level 1;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
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 /dev/null;
# 引用你即将要放置的虚拟主机配置文件
include vhosts/hao32.com;
include vhosts/linuxsense.org;
}

(2)编辑php在fastcgi模式下的配置文件:
# vi fastcgi_params
内容修改为:

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

(2)编辑虚拟主机的配置文件
# cd vhosts/
# vi hao32.com

添加内容如下

server {
listen 80;
server_name hao32.com www.hao32.com;
# 可以选择打开日志
#access_log /var/log/hao32.com/access.log combined buffer=32k;
#error_log /var/log/hao32.com/error.log warn;

location / {
index index.html index.htm index.php;
root /www/wwwroot/hao32.com;

location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8407;
fastcgi_param SCRIPT_FILENAME /www/wwwroot/hao32.com$fastcgi_script_name;
}

location /hao32-status {
stub_status on;
access_log off;
}
}

# vi linuxsense.org
添加内容如下, 这是一个带有discuz!默认rewrite规则的主机事例

server {
listen 80;
server_name linuxsense.org www.linuxsense.org;
# 可以选择打开日志
#access_log /var/log/linuxsense.org/access.log combined buffer=32k;
#error_log /var/log/linuxsense.org/error.log warn;
location / {
index index.html index.htm index.php;
root /www/wwwroot/linuxsense.org;
rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last;
rewrite ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last;
rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last;
rewrite ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2 last;
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8408;
fastcgi_param SCRIPT_FILENAME /www/wwwroot/linuxsense.org$fastcgi_script_name;
}

location /linuxsense-status {
stub_status on;
access_log off;
}
}


作者: hao32 | 可以转载, 转载时务必以超链接形式标明文章原始出处和作者信息及版权声明
网址:http://www.hao32.com/webserver/46.html

Tags: ,

发表评论: