ENGINX(engin x)专为性能优化而开发的,只处理静态页面。

安装准备:

nginx-1.9.4.tar.gz


安装:

解决依赖包

yum -y install pcre-devel openssl openssl-devel zlib-devel


ENGINX--简单篇_nginx--简单篇

创建nginx所需要的账号

useradd -M -s /sbin/nologin nginx


ENGINX--简单篇_nginx--简单篇_02


编译安装nginx

tar zxf nginx-1.9.4.tar.gz -C /usr/src/

cd /usr/src/nginx-1.9.4

./configure --prefix=/usr/local/nginx \

--user=nginx \

--group=nginx \

--with-http_stub_status_module \

--with-http_ssl_module

make && make install


ENGINX--简单篇_nginx--简单篇_03



配置

安装完成后的优化:

ln -s /usr/local/sbin/nginx /usr/local/sbin

查看软链接是否成功:

ls -l /usr/local/sbin/nginx

ENGINX--简单篇_nginx--简单篇_04

检查文件是否有语法错误

nginx -t

ENGINX--简单篇_nginx--简单篇_05

编写简单网页

ENGINX--简单篇_nginx--简单篇_06

启动服务

nginx

ENGINX--简单篇_nginx--简单篇_07

访问测试:

ENGINX--简单篇_nginx--简单篇_08

编辑nginx的服务脚本

#!/bin/bash
#chkconfig: - 100 88
#description: Nginx Server Control Scripts.
N_P="/usr/local/nginx/sbin/nginx"
P_D="/usr/local/nginx/logs/nginx.pid"
#!/bin/bash
#chkconfig: 135 99 100
#description: Nginx server scripts
N_P="/usr/local/nginx/sbin/nginx"
P_D="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
        $N_P
;;
stop)
        kill -s QUIT $(cat $P_D)
;;
restart)
        $0 stop
        $0 start
;;
reload)
        kill -s HUP $(cat $P_D)
;;
*)
        echo "Usage:$0 {start|stop|restart|reload}"
exit 1
;;
esac
exit 0

测试脚本:

ENGINX--简单篇_nginx--简单篇_09

配置nginx的核心和线程

ENGINX--简单篇_nginx--简单篇_10

开启选项避免出现网络堵塞。

ENGINX--简单篇_nginx--简单篇_11

配置主机名,字符集支持,访问状态统计。

ENGINX--简单篇_nginx--简单篇_12

访问测试:

ENGINX--简单篇_nginx--简单篇_13

创建虚拟主机目录:

ENGINX--简单篇_nginx--简单篇_14

更改web页面一配置如下:

ENGINX--简单篇_nginx--简单篇_15

更改web页面二配置如下:

server {
        listen       8000;
        server_name cjl.com;

        location / {
            root   /web/www/2;
            index  index.html index.htm index.php;
        }
    }

ENGINX--简单篇_nginx--简单篇_16

重新启动服务

ENGINX--简单篇_nginx--简单篇_17