Linux下安装nginx

2021/5/23 7:29:18

本文主要是介绍Linux下安装nginx,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

由于在学习spring boot war包部署操作,今天尝试在linux 下安装nginx,记录一下。

一、安装

首先需要安装gcc编译器:yum install gcc-c++

1、Nginx的下载

根目录下:

cd usr/local

wget http://nginx.org/download/nginx-1.17.10.tar.gz

Nginx包下载地址:http://nginx.org/download/nginx-1.17.10.tar.gz

(此包为2020年4月14号的安装包)

2、Nginx依赖包下载地址

(1).gzip模块需要zlib库:在http://www.zlib.net/下载(http://zlib.net/zlib-1.2.8.tar.gz)。

wget http://www.zlib.net/zlib-1.2.11.tar.gz

(2).rewrite模块需要pcre库:在http://www.pcre.org/下载

wget https://ftp.pcre.org/pub/pcre/pcre2-10.31.tar.gz

(3).ssl功能需要openssl库:在http://www.openssl.org/下载

wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz

https://www.openssl.org/source/openssl-1.1.1k.tar.gz

3、 Nginx依赖包的安装

选定**/usr/local**为安装目录:

(1).安装PCRE库

$ cd /usr/local/
$ tar -zxvf pcre2-10.36.tar.gz
$ cd pcre2-10.36
$ ./configure
$ make
$ make install

(2).安装zlib库

$ cd /usr/local/
$ tar -zxvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure
$ make
$ make install

(3).安装ssl

$ cd /usr/local/
$ tar -zxvf openssl-1.1.1k.tar.gz
$ ./config
$ make
$ make install

(4).安装nginx

$ cd /usr/local/
$ tar -zxvf nginx-1.17.10.tar.gz
$ cd nginx-1.17.10 $ ./configure --with-pcre=/usr/local/pcre2-10.36 --with-zlib=/usr/local/zlib-1.2.11 --with-openssl=/usr/local/openssl-1.1.1k --prefix=/usr/local/nginx (此处为nginx 另起文件夹)
$ make
$ make install

​ 其中到make的时候出现了编译错误

``In file included from src/core/ngx_core.h:73:0,from src/core/nginx.c:9:src/core/ngx_regex.h:15:18: 致命错误:pcre.h:没有那个文件或目录#include <pcre.h>

​ 通过查询发现可能是版本问题,降低了pcre的版本之后问题仍然存在,又查询之后安装了pcre库,清除上次编译留下的文件之后再次执行 ./configure 命令

yum -y install pcre-devel

make clean

​ 发现还是不行,崩溃,然后又下载安装了openssl-devel

yum -y install openssl openssl-devel

​ 发现还是不行,不过bug变了,变成了“make: *** 没有规则可以创建“libpcre.ca”需要的目标“build”。 停止”。无奈继续变更pcre的版本

​ 卸载原来的pcre:到了其根目录下,make uninstall,然后退出目录将文件夹删掉,重新下载其他版本的pcre后重复上述操作好了,编译通过:

wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz

​ 最后make install,安装成功!

二、启动nginx

​ Apeache可能占用80端口,apeache端口尽量不要修改

1、修改nginx端口。

Linux 修改路径: /usr/local/nginx/conf/nginx.conf

Windows 下 修改路径: \conf\nginx.conf

修改端口为5566

2、执行启动指令:

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

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xlBOnaGO-1621669135347)(C:\Users\yanwe\AppData\Roaming\Typora\typora-user-images\image-20210409175547438.png)]

检查是否启动成功:

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

3、部分使用命令:

启动:

$ /usr/local/nginx/sbin/nginx

重启:
$ /usr/local/nginx/sbin/nginx -s reload

停止:
$ /usr/local/nginx/sbin/nginx -s stop

测试配置文件是否正常:
$ /usr/local/nginx/sbin/nginx -t

强制关闭:
$ pkill nginx



这篇关于Linux下安装nginx的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程