2 Star 1 Fork 0

zhrun8899 / learning-notes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
centos7安装-nginx.md 5.93 KB
一键复制 编辑 原始数据 按行查看 历史

一、安装准备

首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++、gcc、openssl-devel、pcre-devel和zlib-devel 所以执行如下命令安装

$   yum install gcc-c++
$   yum install pcre pcre-devel
$   yum install zlib zlib-devel
$   yum install openssl openssl--devel

二、安装Nginx

安装之前,最好检查一下是否已经安装有nginx

$   find -name nginx

如果系统已经安装了nginx,那么就先卸载

$   yum remove nginx

下载

首先进入/usr/local目录

$   cd /usr/local

从官网下载最新版的nginx

20180816 最新版本为 nginx-1.9.9.tar.gz $ wget http://nginx.org/download/nginx-1.9.9.tar.gz

解压nginx压缩包

$   tar -zxvf nginx-1.7.4.tar.gz

会产生一个nginx-1.7.4 目录,这时进入nginx-1.7.4目录

$   cd  nginx-1.7.4

接下来安装,使用--prefix参数指定nginx安装的目录,make、make install安装

$   ./configure  $默认安装在/usr/local/nginx,如果需要socket转发,加上 --with-stream
$   make
$   make install

检查安装

如果没有报错,顺利完成后,最好看一下nginx的安装目录

$   whereis nginx

三.配置,启动与停止

安装完毕后,将nginx目录加到系统路径中

vi /etc/profile export PATH=/usr/local/nginx/sbin/:$PATH 然后 source /etc/profile,使生效

验证nginx配置文件是否正确

方法一:进入nginx安装目录sbin下,输入命令./nginx -t 看到如下显示 nginx.conf syntax is ok,nginx.conf test is successful 说明配置文件正确! 方法二:在启动命令-c前加-t

启动

nginx -c /usr/local/nginx/conf/nginx.conf

停止:

1.nginx -s stop

2.kill

ps -ef|grep nginx kill -QUIT 2072 kill -TERM 2132 kill -INT 2132 pkill -9 nginx

重启Nginx服务

方法一:进入nginx可执行目录sbin下,输入命令./nginx -s reload 即可 方法二:查找当前nginx进程号,然后输入命令:kill -HUP 进程号 实现重启nginx服务

Linux Nginx安装以及可能出现错误 2016年04月21日 21:55:30 三产 阅读数:7385 标签: centos nginx linunx 更多 个人分类: Linux nginx 版权声明:本文为博主原创文章,转载请标注出处 https://blog.csdn.net/u012885276/article/details/51213382 转载请标明出处 http://coderknock.com 安装过程 从 http://nginx.org/download/nginx-1.9.15.tar.gz 下载nginx包(或者wget http://nginx.org/download/nginx-1.9.15.tar.gz直接在Linux上用命令下载)

解压并转到目录下

tar -zxvf nginx-1.9.15.tar.gz cd nginx-1.9.15

设置一下配置信息 ./configure --prefix=/usr/local/nginx ,或者不执行此步,直接默认配置

编译安装

make make install

make的过程是把各种语言写的源码文件,变成可执行文件和各种库文件; make install是把这些编译出来的可执行文件和库文件复制到合适的地方。

可能出现错误 在配置信息./configure --prefix=/usr/local/nginx 的时,出现错误: /configure: error: the HTTP rewrite module requires the PCRE library.

解决方法:安装pcre

yum -y install pcre pcre-devel

y 是跳过所有需要手动确认的环节

缺少ssl错误,错误信息如下: ./configure: error: the HTTP cache module requires md5 functions from OpenSSL library. You can either disable the module by using --without-http-cache option, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-http_ssl_module --with-openssl= options.

解决方法:安装openssl

yum -y install openssl openssl-devel 1 缺少编译器,错误信息如下: ./configure: error: C compiler cc is not found

解决方法:安装gcc-c++

yum -y install gcc-c++ autoconf automake

autoconf是自动配置,automake是自动编译

缺少zlib包,错误信息如下: ./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using –without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using –with-zlib= option.

解决方法:安装zlib

yum install -y zlib-devel 1 确实libxml2,错误信息如下: ./configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries. You can either do not enable the module or install the libraries.

解决方法:

yum -y install libxml2 libxml2-dev yum -y install libxslt-devel

http_image_filter_module是nginx提供的集成图片处理模块,需要gd-devel的支持,错误信息如下: ./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.

解决方法:

yum -y install gd-devel

缺少ExtUtils,错误信息如下: ./configure: error: perl module ExtUtils::Embed is required

解决方法:

yum -y install perl-devel perl-ExtUtils-Embed

缺少GeoIP,错误信息如下: ./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library.

解决方法:

yum -y install GeoIP GeoIP-devel GeoIP-data

安装完成后启动 安装成功后 /usr/local/nginx 目录下如下 fastcgi.conf koi-win nginx.conf.default fastcgi.conf.default logs scgi_params fastcgi_params mime.types scgi_params.default fastcgi_params.default mime.types.default uwsgi_params html nginx uwsgi_params.default koi-utf nginx.conf win-utf

启动 确保系统的 80 端口没被其他程序占用,运行/usr/local/nginx/nginx 命令来启动 Nginx,

netstat -ano|grep 80

如果查不到结果后执行,有结果则忽略此步骤(ubuntu下必须用sudo启动,不然只能在前台运行)

sudo /usr/local/nginx/nginx

打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。

定义静态文件位置: location /demoSystem.html { root /var/www/secretMail/; } 定义访问的springboot后端: location /secretMail/ { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:10092; } 定义要节点: location / { root /var/www/secretMail/; index index.html index.htm; if ( !-e $request_filename ) { rewrite ^/(.*) /index.html last; break; }

}

四.yum安装:

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx -y
1
https://gitee.com/zhrun8899/learning-notes.git
git@gitee.com:zhrun8899/learning-notes.git
zhrun8899
learning-notes
learning-notes
master

搜索帮助