1.Nginx依赖程序安装

[root@Linux tool]# yum -y install zlib pcre pcre-devel openssl openssl-devel gcc-c++

2.源码编译安装Nginx

#useradd -s /sbin/nologin www

[root@Linux tool]# wget -c http://nginx.org/download/nginx-1.14.2.tar.gz

[root@Linux tool]# tar zxvf nginx-1.14.2.tar.gz 

[root@Linux tool]# cd nginx-1.14.2

[root@Linux nginx-1.14.2]# ./configure --user=www  --group=www --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-  path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.pid --with-http_stub_status_module --with-http_gzip_static_module --with-pcre

[root@Linux nginx-1.14.2]# make -j 8 && make install 

[root@Linux /]# /usr/local/nginx/sbin/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@Linux /]# /usr/local/nginx/sbin/nginx    

3.Nginx配置文件

[root@Linux conf]# cat nginx.conf

user nginx nginx; 

worker_processes  3;

error_log  logs/error.log  notice;

pid        logs/nginx.pid;

worker_rlimit_nofile  65535;

events {

    use epoll;

    worker_connections  6000;

}

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;

    sendfile        on;

    keepalive_timeout  30;

    server_names_hash_bucket_size 128; 

    client_max_body_size 30m;

    client_header_buffer_size 32k;

    large_client_header_buffers  4 32k;

    gzip  on;

    gzip_min_length 1k;

    gzip_buffers  4  16k; 

    gzip_http_version  1.1;

    gzip_comp_level  2;

    gzip_types  text/plain  application/x-javascript text/css application/xml;

    gzip_vary on;

    server {

        listen       80;

        server_name  localhost;

        location / {

            root   /www/html/;

            index  index.html  index.php;

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

          location ~ \.php$ {

            root         /www/html/;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME   /www/html$fastcgi_script_name;

            include        fastcgi_params;

          }

   }

4.Nginx的管理与维护

1)检查Nginx配置文件的正确性

[root@Linux /]# /usr/local/nginx/sbin/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

2)显示Nginx的版本以及相关编译信息

[root@Linux /]# /usr/local/nginx/sbin/nginx -v

nginx version: nginx/1.14.2

[root@Linux /]# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.14.2

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 

configure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.pid --with-http_stub_status_module --with-http_gzip_static_module --with-pcre

3)Nginx的启动

[root@Linux /]# /usr/local/nginx/sbin/nginx 

[root@Linux /]# ps -ef|grep nginx

root      3843     1  0 2月03 ?       00:00:00 nginx: master process ./nginx

nginx     3844  3843  0 2月03 ?       00:00:00 nginx: worker process

nginx     3845  3843  0 2月03 ?       00:00:00 nginx: worker process

nginx     3846  3843  0 2月03 ?       00:00:00 nginx: worker process

root     22512  8770  0 09:34 pts/1    00:00:00 grep --color=auto nginx

4)Nginx的关闭

#kill  pid              #pid是指Nginx进程号

4)Nginx的平滑重启

[root@Linux run]# cat /usr/local/nginx/logs/nginx.pid            

3843

[root@Linux run]# kill -HUP 3843

5)测试页面如下:

安装与配置Nginx_Web