一、安装Nginx
1、安装支持软件
[root@localhost ~]# yum -y install pcre-devel zlib-devel
|
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
|
[root@localhost ~]# cd /data/
[root@localhost data]# tar zxf nginx-1.0.8.tar.gz
[root@localhost data]# cd nginx-1.0.8
[root@localhost nginx-1.0.8]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@localhost nginx-1.0.8]# make
[root@localhost nginx-1.0.8]# make install
|
[root@localhost nginx-1.0.8]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost nginx-1.0.8]# ls -l /usr/local/sbin/nginx
lrwxrwxrwx 1 root root 27 05-30 17:07 /usr/local/sbin/nginx -> /usr/local/nginx/sbin/nginx
|
[root@localhost nginx-1.0.8]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
|
[root@localhost nginx-1.0.8]# nginx
|
[root@localhost nginx-1.0.8]# netstat -anpt | grep nginx
tcp
0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6229/nginx: master
[root@localhost nginx-1.0.8]# elinks
http://localhost
//使用
elinks浏览器
|
[root@localhost nginx-1.0.8]# killall -s HUP nginx
//重新加载配置文件
[root@localhost nginx-1.0.8]# killall -s QUIT nginx
//关闭进程
|
[root@localhost ~]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Server Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# /etc/init.d/nginx restart
[root@localhost ~]# chkconfig nginx on
|
[root@localhost /]# vim /usr/local/nginx/conf/nginx.conf
http {
…... //省略部分信息
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
以下内容为自行添加
location ~ /status { //访问位置为
/status
stub_status on; //打开状态统计功能
access_log off; //关闭此位置的日志记录
}
}
}
[root@localhost ~]# /etc/init.d/nginx restart
|
新的配置生效以后,在浏览器中访问Nginx服务器的/statux网站位置,可以看到当前的状态统计信息,其中,“Active connections”表示当前的活动连接数;而“server accepts handled requests”表示已经处理的连接信息,三个数字依次表示已处理的连接数、成功的TCP握手次数、已处理的请求数。
[root@localhost /]# mkdir -p /var/www/baidu
[root@localhost /]# echo "www.aaa.com" > /var/www/aaa/index.html
[root@localhost /]# mkdir -p /var/www/bbb
[root@localhost /]# echo "www.bbb.com" > /var/www/bbb/index.html
|
…... //省略部分信息
http {
…... //省略部分信息
server {
listen 80;
server_name www.aaa.com;
charset utf-8;
access_log logs/aaa.com.access.log main;
location / {
root /var/www/bbb;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.bbb.com;
charset utf-8;
access_log logs/bbb.com.access.log main;
location / {
root /var/www/bbb;
index index.html index.htm;
}
}
}
|
[root@localhost ~]# yum -y install ncurses-devel
//首先安装依赖包
[root@localhost ~]# tar -zxf mysql-5.1.55.tar.gz
[root@localhost ~]# cd mysql-5.1.55
[root@localhost mysql-5.1.55]# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-clollation=utf8_general_ci --with-extra-charsets=gbk,gb2312
[root@localhost mysql-5.1.55]# make && make install
|
[root@localhost mysql-5.1.55]# cp support-files/my-medium.cnf /etc/my.cnf
[root@localhost mysql-5.1.55]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.1.55]# chmod a+x /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.1.55]# chkconfig --add mysqld
[root@localhost mysql-5.1.55]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@localhost mysql-5.1.55]# ln -s /usr/local/mysql/lib/mysql/* /usr/lib/
[root@localhost mysql-5.1.55]# ln -s /usr/local/mysql/include/mysql/* /usr/include/
|
[root@localhost mysql-5.1.55]# useradd -M -u 27 -s /sbin/nologin mysql
[root@localhost mysql-5.1.55]# cd /usr/local/mysql/bin/
[root@localhost bin]# ./mysql_install_db --user=mysql
[root@localhost bin]# chown -R root:mysql /usr/local/mysql/
[root@localhost bin]# chown -R mysql /usr/local/mysql/var/
|
[root@localhost bin]# service mysqld start
[root@localhost bin]# mysqladmin -u root password 'pwd123'
[root@localhost bin]# mysql -u root -p
|
[root@localhost ~]# tar -xzf php-5.3.6.tar.gz
[root@localhost ~]# cd php-5.3.6/
[root@localhost php-5.3.6]#./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql/ --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm
[root@localhost php-5.3.6]# make
[root@localhost php-5.3.6]# make install
|
[root@localhost php-5.3.6]# cp php.ini-development /usr/local/php5/php.ini
[root@localhost php-5.3.6]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[root@localhost php-5.3.6]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/
|
[root@localhost ~]# tar -xzf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
[root@localhost ~]# cd ZendGuardLoader-php-5.3-linux-glibc23-x86_64
[root@localhost ~]# cp ZendGuardLoader.so /usr/local/php5/lib/php/
[root@localhost ~]# vim /usr/local/php5/php.ini
…… //省略部分信息
//在文件中添加
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
|
[root@localhost ~]# cd /usr/local/php5/etc
[root@localhost ~]# cp php-fpm.conf.default php.fpm.conf
[root@localhost ~]# vim php-fpm.conf
…… //省略部分信息
25 pid = run/php-fpm.pid
//确认pid文件位置
122 user = nginx
//运行用户
123 group = nginx
//运行组
157 pm.start_servers = 20
//启动时开启的进程数
162 pm.min_spare_servers = 5
//最小空闲进程数
167 pm.max_spare_servers = 35
//最多空闲进程数
[root@localhost etc]# /usr/local/sbin/php.fpm
[root@localhost etc]# netstat –anpt | grep php-fpm
tcp
0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4448/php-fpm.conf)
|
[root@localhost /]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Server Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/sbin/php-fpm"
PIDF_FPM="/usr/local/php5/var/run/php-fpm.pid"
case "$1" in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF) //根据
PID终止Nginx进程
kill -s QUIT $(cat $PIDF_FPM) //根据
PID终止php-fpm进程
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
|
server {
listen 80;
server_name www.benet.com;
charset utf-8;
access_log logs/benet.com.access.log main;
location / {
root /var/www/benet;
index index.html index.htm;
}
添加以下内容
location ~ \.php$ { //访问
.php页面的配置段
root /var/www/dong; //PHP网页文档根目录
fastcgi_pass 127.0.0.1:9000; //php-fpm的监听地址
fastcgi_index index.php; //PHP首页文件
include fastcgi.conf; //包括
fastcgi.conf样本配置
}
}
|
[root@localhost benet]# vim /var/www/benet/test.php
//手动添加
<?php
phpinfo;
?>
|
本文出自 “七越” 博客,转载请与作者联系!