Nginx Linux安装与部署

1.安装编译工具及库文件

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

2.首先要安装 PCRE(PCRE 作用是让 Nginx 支持 Rewrite 功能)

yum install pcre pcre-devel -y

rpm -qa pcre pcre-devel

3.建立nginx管理用户:

groupadd -r nginx

useradd  –s /sbin/nologin -g nginx –M nginx

id nginx

4.下载nginx软件并解压源码安装

mkdir –p /home/bqh/tools

cd /home/bqh/tools

wget –q http://nginx.org/download/nginx-1.6.3.tar.gz

tar zxf nginx-1.6.3.tar.gz

./configure –prefix=/application/nginx-1.6.3 –user=nginx –group=nginx –with-http_ssl_module –with-http_stub_status_module

若执行上面命令提示:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using –with-openssl= option.

解决方法:

yum -y install openssl openssl-devel

再执行./configure命令….

Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library

nginx path prefix: “/application/nginx-1.6.3”
nginx binary file: “/application/nginx-1.6.3/sbin/nginx”
nginx configuration prefix: “/application/nginx-1.6.3/conf”
nginx configuration file: “/application/nginx-1.6.3/conf/nginx.conf”
nginx pid file: “/application/nginx-1.6.3/logs/nginx.pid”
nginx error log file: “/application/nginx-1.6.3/logs/error.log”
nginx http access log file: “/application/nginx-1.6.3/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
nginx http uwsgi temporary files: “uwsgi_temp”
nginx http scgi temporary files: “scgi_temp”

 出现以上结果代表ok的,接着我们执行:

make && make install

如果执行make这一步的时候只提示:make[1]: Leaving directory `/home/bqh/tools/nginx-1.6.3′不用管它,继续执行make install 即可。

注意:此方法只针对 错一行,如果你安装nginx走到make这一步的时候, 错了很多行的make解决办法就不一样了,比如说:有时候安装nginx需要指定 pcre 的源码目录等。

介绍:

–prefix=软件安装到哪里

–user=用户 (默认nobody)

–group=用户组 (默认nobody)

–with-http_ssl_module  加密模块

–with-http_stub_status_module  状态模块

cd ..

ln -s /application/nginx-1.6.3/ /application/nginx   做个软连接(快捷方式)隐藏版本

安装完nginx后,并不能直接对外提供服务,需要先启动nginx才行。

如果Ngnix软件不是本人装的,那么我们可以用以下命令查看安装路径及参数信息:

/application/nginx/sbin/nginx –V

启动nginx :

启动前检查配置文件语法:/application/nginx/sbin/nginx -t

我们在本地用curl 127.0.0.1 检查nginx启动的实际效果如下:

到这里,nginx服务已经完成搭建了。若搭建静态 站,我们可以把静态 页放到/application/nginx/html/下即可。

例如:

下面我们进入安装nginxd的目录下:/application/nginx-1.6.3/conf

我们去除掉默认配置文件里的注释和空行并重定向到nginx.conf文件里,同时我们需要配置如下:

egrep -v “#|^$” nginx.conf.default >nginx.conf   //去掉包含# 和空行的内容

nginx.conf具体配置如下:

在/application/nginx/html目录下一个静态文件 index.html

 我们通过hosts来解析

同样在windows系统,配置一下host在“C:WindowsSystem32driversetc”下的hosts中配置一下域名解析

正确指向后在telnet一下80端口看一下是否可以与端口通信(如果telnet提示没有此命令是没有安装客户端,在启用或禁用windows功能处安装后再操作即可)

打开浏览器,输入www.test.com会得到以下结果,就说明外 访问成功

Nginx Linux安装与部署

测试都成功,ok!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

nginx常用命令:

/application/nginx/sbin/nginx -t                       启动前检查配置文件语法

/application/nginx/sbin/nginx                          启动nginx

/application/nginx/sbin/nginx –V                     查看安装路径及参数信息

/application/nginx/sbin/nginx -s reload           重新载入配置文件

/application/nginx/sbin/nginx -s reopen          重启 Nginx

/application/nginx/sbin/nginx -s stop              停止 Nginx

nginx软件功能模块说明:

  nginx http功能模块:

ngx_http_core_module   //包括一些核心的http参数配置,对应nginx的配置为http区块部分

ngx_http_access_module   //访问控制模块,用来控制 站用户对nginx的访问

ngx_http_gzip_module   //压缩模块,对nginx返回的数据压缩,属于性能优化模块

ngx_http_fastcgi_module   //fastcgi模块,和动态应用相关的模块,例如php

ngx_http_proxy_module   //代理模块

ngx_http_upstream_module  //负载均衡模块,实现 站的负载均衡功能及节点的健康检查

ngx_http_rewrite_module  //url地址重写模块

ngx_http_limit_conn_module  //限制用户并发连接数及请求数模块

ngx_http_limit_req_module  //限制nginx request processing rate 根据定义的key

ngx_http_log_module  //访问日志模块,以指定的格式记录nginx客户访问日志等信息

ngx_http_auth_basic_module  //web认证模块,设置web用户通过账 密码访问nginx

ngx_http_ssl_module  //ssl模块,用于加密的http连接,如https

ngx_http_stub_status_module  //记录nginx基本访问状态信息等的模块

文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树首页概览92901 人正在系统学习中

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年1月5日
下一篇 2019年1月5日

相关推荐