Nginx软件部署配置过程

---恢复内容开始---

注意:博主使用的系统为:

[root@web01 ~]# uname -a
Linux web01 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

 编译安装步骤

 第一步、配置

01. 指定软件安装路径(默认路径/usr/local

02. 开启相应功能

 第二步、编译

把代码转换成计算机可以识别的二进制信息make

 第三步、编译安装

make install

编译安装Nginx软件过程

第一步、解决Nginx软件的依赖包、下载Nginx

Nginx软件的依赖包有两个:pcre包和openssl包

pcre:兼容perl语言正则表达式,perl compatible regular expressions

         rewirte模块 参数信息(perl方式定义正则表达式)

opensslhttps

所有安装依赖软件,软件后面加上devel 

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

下载nginx:

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

[root@web01 tools]# ll

total 892

-rw-r--r-- 1 root root 910812 Oct 24 10:26 nginx-1.10.2.tar.gz

[root@web01 tools]# pwd

/server/tools

 第二步、解压软件进行配置、创建管理用户

[root@web01 tools]# tar xf nginx-1.10.2.tar.gz

[root@web01 tools]# ll

total 896

drwxr-xr-x 8 1001 1001   4096 Oct 18  2016 nginx-1.10.2

-rw-r--r-- 1 root root 910812 Oct 24 10:26 nginx-1.10.2.tar.gz

[root@web01 tools]# cd nginx-1.10.2

[root@web01 nginx-1.10.2]#

[root@web01 nginx-1.10.2]# useradd -s /sbin/nologin www -M

[root@web01 nginx-1.10.2]# id www

uid=2223(www) gid=2223(www) groups=2223(www)

  

[root@web01 nginx-1.10.2]# ./configure --prefix=/application/nginx-1.10.2 --user=www --group=www --with-http_stub_status_module  --with-http_ssl_module

--prefix:表示指定软件安装到哪个目录中,指定目录不存在会自动创建

--user/--groupnginx工作进程由哪个用户运行管理

--with-http_stub_status_module:表示启动nginx状态模块功能(用户访问nginx的网络信息)

--with-http_ssl_module:启动https功能模块

 第三步、编译 && 编译安装

make && make install

 第四步、启动服务

[root@web01 application]# /application/nginx/sbin/nginx

[root@web01 application]# ps -ef |grep nginx

root  15342      0 10:56 ?   00:00:00 nginx: master process /application/nginx/sbinnginx  主进程

www   15343  15342  0 10:56 ?  00:00:00 nginx: worker process  处理进程

root  15345  12539  0 10:56 pts/0    00:00:00 grep --color=auto nginx

 至此,Nginx就已经安装完成了

软件安装目录信息详解 

 conf    ---- 软件配置文件保存目录

 html    ---- 网站站点目录

 logs     ---- 日志文件保存目录

 sbin     ---- nginx命令保存目录

 conf目录内容

nginx.conf               --- nginx程序的主配置文件

nginx.conf.default    --- nginx配置备份文件

 这里可以精简一下配置文件信息,因为好多注释,利用下面命令精简:

 egrep -v "#|^$" nginx.conf.default >nginx.conf

配置文件详细说明 

[root@web01 nginx]# cat conf/nginx.conf

worker_processes  1;              ##worker进程数量

events {

    worker_connections  1024;        ##每个worker进程支持的最大连接数

}

http {

    include       mime.types;        ##Nginx支持的媒体类型库文件

    default_type  application/octet-stream;  ##默认的媒体类型

    sendfile        on;            ##开启高效传输模式

    keepalive_timeout  65;         ##连接超时

    server {

        listen       80;            ##提供服务的端口,默认是80

        server_name  www.zxpo.com;  ##提供服务的域名主机名

        location / {

            root   html/www;         ##站点的根目录,相当于Nginx的安装目录

            index  oldboy.html index.htm;  ##默认的首页文件,多个用空格分开

        }

        error_page   500 502 503 504  /50x.html; ##出现对应的状态码,使50x.html

        location = /50x.html {

            root   html;     ##指定对应的站点目录为html

        }

    }

}

 nginx软件启动重启方式

启动方法

/applocation/nginx/sbin/nginx

停止方法

/applocation/nginx/sbin/nginx -s stop

平滑重启方法

/applocation/nginx/sbin/nginx -s reload

检查配置文件语法

/applocation/nginx/sbin/nginx -t

查看怎么部署的

/applocation/nginx/sbin/nginx -V

 以上步骤配置完成后,可以进行一个简单的静态网页编写,网上有很多代码,可以自己去复制,这里我自己设置了一个简单的静态网页:

[root@web01 www]# cat index.html

<html>

<meta charset="utf-8">

<head>

<title>zxpo--矢志少年</title>

</head>

<body>

矢志少年

<table border=1>

<tr> <td>01</td> <td> </td> </tr>

<tr> <td>02</td> <td> </td> </tr>

<tr> <td>03</td> <td> </td> </tr>

</table>

<a href="http://www.zxpo.top">

<img src="stu.png" />

</a>

</body>

</html>

 注意:设置完成后要是想验证的话,一定要把hosts解析弄好。

 

 

 

 

 


posted @ 2017-10-30 17:20  酷酷的二连长  阅读(567)  评论(0编辑  收藏  举报