Nginx: installation configuration using virtual hosts and web site monitoring module

一.源码包安装Nginx。
1.安装Nginx。
1)安装依赖程序。
[root@Centos ~]# yum -y install pcre-devel zlib-devel gcc gcc-c++ openssl-devel zlib
2)创建nginx中账户。
[root@Centos ~]# useradd -M -s /sbin/nologin nginx
3)配置,编译,安装源码包
[root@nginx nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx && make && make install

--with-http_dav_module:启用支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)
--with-http_stub_status_module:启用支持(获取Nginx上次启动以来的工作状态)
--with-http_addition_module:启用支持(作为一个输出过滤器,支持不完全缓冲,分部分相应请求)
--with-http_sub_module:启用支持(允许一些其他文本替换Nginx相应中的一些文本)
--with-http_flv_module:启用支持(提供支持flv视频文件支持)
--with-http_mp4_module:启用支持(提供支持mp4视频文件支持,提供伪流媒体服务端支持)

2. Optimize nginx, nginx configuration service .
1) nginx optimization program execution location.
[@ Centos the root-Nginx 1.6.0] LN # -s / usr / local / Nginx / sbin / Nginx / usr / local / sbin
2) Nginx management.
nginx -t check the integrity of the configuration file
nginx nginx open service
killall -s HUP nginx restart nginx
killall -s the QUIT nginx nginx stop service
3) the need to write the service control script.

#!/bin/bash
#chkconfig: 35 90 30
#description: Nginx Server
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

4) Add a system service, and is set to boot from Kai.
[@ Centos the root /] # X /etc/init.d/nginx the chmod +
[@ Centos the root /] # the chkconfig --add Nginx
[@ Centos the root /] # 35 --level the chkconfig Nginx ON
3.nginx main configuration file .
1) global configuration.
user nginx; management nginx default account
worker_processes 1; number of processes, according to the cpu setting, a cpu a process
pid logs / nginx.pid; nginx service starts after storage service id location
error_log logs / error.log; error log position
2) I / o event configuration.
Events
use epoll; management model uses
worker_connections 1024; the number of connections per process handled
3) http configuration.
keepalive_timeout 65; http connection hold time, usually 10s
sendfile ON; start access log
server a virtual server on behalf of a host
root html; website root directory location
index index.html index.htm; homepage
4. configuration based virtual hosting.
server {
192.168.200.20:80 the listen;
charset UTF-. 8;
server_name www.benet.com;
access_log logs / www.benet.com.access.log;
the error_log logs / www.benet.com.access.lig;
LOCATION / {
the root / var / WWW / benetcom /;
index index.html insex.php;
}
LOCATION / Status {
stub_status ON;
access_log OFF;
}
}
5. The statistical website visits.
http://www.benet.com/status
Here Insert Picture Description
three figures as follows:
the number of connections has been processed
successfully number handshake
requests

Published 52 original articles · won praise 4 · views 10000 +

Guess you like

Origin blog.csdn.net/HCY_2315/article/details/104394454