nginx源码编译安装及配置文件说明

nginx源码编译安装

安装nginx的依赖包(pcre-devel openssl-devel)

[root@anuo ~]# yum install pcre-devel openssl-devel -y

创建管理用户 nginx

[root@anuo ~]# useradd -s /sbin/nologin -M nginx

下载nginx源码包

[root@anuo opt]# wget http://nginx.org/download/nginx-1.10.2.tar.gz

解压软件

tar xf nginx-1.10.2.tar.gz
[root@anuo opt]# tar xf nginx-1.10.2.tar.gz -C /usr/src/
[root@anuo opt]# cd /usr/src/nginx-1.10.2/

nginx软件编译安装过程

配置软件,在软件的解压目录中

[root@anuo nginx-1.10.2]# ./configure --prefix=/usr/local/nginx-1.10.2 --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module

编译参数说明:

 –prefix           --表示指定软件安装到哪个目录中,指定目录不存在会自动创建
 –user/–group       --nginx工作进程由哪个用户运行管理
 –with-http_stub_status_module   --启动nginx状态模块功能(用户访问nginx的网络信息)
 –with-http_ssl_module           --启动https功能模块

确认配置是否正确

[root@anuo nginx-1.10.2]# echo $? 
0

编译软件

[root@anuo nginx-1.10.2]# make

编译安装

[root@anuo nginx-1.10.2]# make install

创建软连接

[root@anuo nginx-1.10.2]# cd /usr/local/
[root@anuo local]# ln -s /usr/local/nginx-1.10.2/ /usr/local/nginx

启动程序

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

检查是否启动

[root@anuo local]# ps -ef | grep nginx
root       8741      1  0 08:31 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx      8742   8741  0 08:31 ?        00:00:00 nginx: worker process      
root       8744   1802  0 08:31 pts/0    00:00:00 grep nginx

检查端口信息

[root@anuo local]# lsof -i:80
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   8741  root    6u  IPv4  19348      0t0  TCP *:http (LISTEN)
nginx   8742 nginx    6u  IPv4  19348      0t0  TCP *:http (LISTEN)

服务安装完成了

nginx命令简化方法

[root@anuo local]# echo 'export PATH=/usr/local/nginx/sbin:$PATH'>>/etc/profile
[root@anuo local]# source /etc/profile
[root@anuo local]# echo $PATH
/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

nginx 目录结构

[root@anuo nginx]# ll
总用量 36
drwx------ 2 nginx root 4096 5月  14 08:31 client_body_temp
drwxr-xr-x 2 root  root 4096 5月  14 08:26 conf  #配置文件保存目录 
drwx------ 2 nginx root 4096 5月  14 08:31 fastcgi_temp
drwxr-xr-x 2 root  root 4096 5月  14 08:26 html  #站点目录 
drwxr-xr-x 2 root  root 4096 5月  14 08:31 logs  #nginx 服务相关日志文件保存目录(错误日志访问日志)
drwx------ 2 nginx root 4096 5月  14 08:31 proxy_temp
drwxr-xr-x 2 root  root 4096 5月  14 08:26 sbin  # 服务命令目录(只有一个nginx文件)
drwx------ 2 nginx root 4096 5月  14 08:31 scgi_temp
drwx------ 2 nginx root 4096 5月  14 08:31 uwsgi_temp

nginx.conf 配置文件说明

将配置文件的注释和空行去掉方便查看
[root@anuo conf]# egrep -v "#|^$" nginx.conf.default > nginx.conf

[root@anuo conf]# cat nginx.conf

worker_processes  1;                        ← worker 进程数量 
events {                                    ←事件区块     
    worker_connections  1024;      ←每个worker进程可以处理的连接数 
}           
http {                                      ← HTTP 区块    
    include       mime.types;          ←支持的媒体文件     
    default_type  application/octet-stream; ←默认的媒体类型     
    sendfile        on;                     ←高效传输模式     
    keepalive_timeout  65;                  ←超时时间     
    server {                                 ← server 区块        
        listen       80;                    ←监听的端口         
        server_name  localhost;             ←域名         
        location / {                        ←location区块             
            root   html;                     ←站点目录             
            index  index.html index.htm;     ←首页文件        
            }                                                           
        error_page   500 502 503 504  /50x.html;  ← 错误信息配置         
        location = /50x.html {                             
            root   html;                           
        }                                          
    }                                    
}                              

nginx使用命令参数

[root@anuo conf]# nginx     --启动服务

[root@anuo conf]# nginx -s stop     --关闭服务

[root@anuo conf]# nginx -t          --修改了配置文件检查下语法

[root@anuo conf]# nginx -s reload   --重新加载

[root@anuo conf]# nginx -V          --查看编译参数信息
nginx version: nginx/1.10.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.10.2 --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module

猜你喜欢

转载自blog.51cto.com/13744837/2116910