nginx服务器安装点滴
/ / 点击 /在高连接并发的情况下,Nginx是Apache服务器不错的替代品。 Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一. 能够支持高达 50,000 个并发连接数的响应。比较强。
Freebsd7.0 下安装 php(fast-cgi) + mysql + zend
下载源码:1
2
3
4
5
6
7
8cd /usr/ports/databases/mysql50-server/
make fetch
cd /usr/ports/www/nginx-devel/
make fetch
cd /usr/ports/lang/php5
make fetch
cd /usr/ports/www/lighttpd
make fetch
编译安装:
MySQL1
2
3
4
5cd /usr/ports/distfiles/
tar -jxf mysql-5.0.51a.tar.gz
cd mysql-5.0.51a
./configure —prefix=/usr/local/vhost/mysql —with-charset=utf8 —with-extra-charsets=all —with-big-tables —with-pthread
make &&make install
Nginx1
2
3
4
5
6
7cd /usr/ports/devel/pcre
make install clean
cd /usr/ports/distfiles/
tar -jxf nginx-0.6.30.tar.gz
cd nginx-0.6.30
./configure —prefix=/usr/local/vhost/nginx —with-http_ssl_module—with-http_gzip_static_module —with-http_stub_status_module—with-http_sub_module
make &&make install
Lighttpd
(安装lighttpd是为了得到启动fastcgi进程)1
2
3tar -jxf lighttpd-1.4.19.tar.bz2
cd lighttpd-1.4.19
./configure —prefix=/usr/local/vhost/lighttpd
Php1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25cd /usr/ports/textproc/libxml2
make install clean
cd /usr/ports/ftp/curl
make install clean
cd /usr/ports/graphics/jpeg
make install clean
cd /usr/ports/graphics/png
make install clean
cd /usr/ports/devel/gettext
make install clean
cd /usr/ports/distfiles/
tar -jxf php-5.2.6.tar.bz2
cd php-5.2.6
./configure --prefix=/usr/local/vhost/php—with-mysql=/usr/local/vhost/mysql --enable-fastcgi \
--enable-sockets—enable-ftp --enable-zip --enable-mbstring --enable-mbregex—enable-calendar \
--with-curl=/usr/local/clude --with-curlwrappers—disable-debug --enable-inline-optimization \
--with-zlib --with-gd—with-kerberos --with-gettext --enable-force-cgi-redirect—with-jpeg-dir=/usr/local/include \
--with-png-dir=/usr/local/include—with-bz2 --enable-pcntl --with-iconv
make && make install
cp php.ini-dist /usr/local/vhost/php/lib/php.ini
配置
MySQL1
2
3
4
5
6cd /usr/local/vhost/mysql
pw adduser mysql -d /dev/null -s /sbin/nologin
bin/mysql_install_db
cp share/mysql/mysql.server ./
chmod +x mysql.server
chown -R mysql ./
启动1
/usr/local/vhost/mysql/mysql.server start
配置nginx
代码:1
2
3
4cd /usr/local/vhost/nginx/
pw adduser webuser -d /dev/null -s /sbin/nologin
cp /usr/local/vhost/lighttpd/bin/spawn-fcgi ./sbin/
rm -rf /usr/local/vhost/lighttpd
vi sbin/php.sh
代码:1
2
3#!/bin/sh
/usr/local/vhost/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 8 -u webuser \
-f /usr/local/vhost/php/bin/php-cgi
代码:1
chmod +x sbin/php.sh
启动php for fast-cgi
代码:
sbin/php.sh
vi conf/enable_php
代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/vhost/nginx/html$fastcgi_script_name;
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;
}
vi conf/nginx.conf
代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66user webuser webuser;
worker_processes 1;
events {
worker_connections 4096;
use kqueue;
}
http {
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;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
client_max_body_size 5m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
send_lowat 12000;
keepalive_timeout 75 20;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
if (-d $request_filename){
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
location /nginx_status {
stub_status on;
access_log off;
}
include enable_php;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
测试配置文件
代码:1
2
3sbin/nginx -t
2008/05/08 11:50:19 [info] 3336#0: the configuration file /usr/local/vhost/nginx/conf/nginx.conf syntax is ok
2008/05/08 11:50:19 [info] 3336#0: the configuration file /usr/local/vhost/nginx/conf/nginx.conf was tested successfully
vi html/phpinfo.php
代码:1
2
3<?php
phpinfo();
?>
启动测试
代码:1
/usr/local/vhost/nginx/sbin/nginx
在浏览器里输入1
http://192.168.29.128/phpinfo.php
安装配置phpMyadmin1
2
3
4
5
6cd /usr/ports/databases/phpmyadmin/
make fetch
cd /usr/ports/distfiles
tar -jxf phpMyAdmin-2.11.6-all-languages.tar.bz2
mv phpMyAdmin-2.11.6-all-languages /usr/local/vhost/nginx/html/dbadmin
此时MySQL的root没有密码,如果一切正常可以用
http://192.168.29.128/dbadmin/index.php来管理MySQL了
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
根据上面的文章已经自己的情况就可以搭建自己的nginx服务器了。
下面是我的一点补充:
虚拟主机配置:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35server {
listen 80;
server_name s1.abc.com;
root /home/www/vhosts/s1_abc_com;
error_page 404 http://s1.abc.com;
access_log logs/s1.abc.com.access.log;
error_log logs/s1.abc.com.error.log;
location / {
root /home/www/vhosts/s1_abc_com/;
index index.html index.htm index.php;
}
# serve static files directly
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
access_log off;
expires 30d;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/vhosts/s1_abc_com$fastcgi_script_name;
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_intercept_errors on;
}
location ~ /.ht {
deny all;
}
}
安装Zend的时候一点注意的地方
1 | ln -s /usr/lib/libm.so /usr/lib/libm.so.4 |
如果./install的时候出错,试试./install-tty 来安装
几个管理脚本:
察看进程:
1 | #!/bin/sh |
启动Mysql1
2#!/bin/sh
/usr/local/vhost/mysql/mysql.server start
停止Mysql1
2#!/bin/sh
/usr/local/vhost/mysql/mysql.server stop
Reload nginx配置,不必重起nginx1
2#!/bin/sh
kill -HUP cat /usr/local/vhost/nginx/logs/nginx.pid
启动webserver1
2
3#!/bin/sh
/usr/local/vhost/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 8 -u webuser -f /usr/local/vhost/php/bin/php-cgi
/usr/local/vhost/nginx/sbin/nginx -c /usr/local/vhost/nginx/conf/nginx.conf
关闭webserver1
2
3#!/bin/sh
killall nginx
killall php-cgi