编译安装Nginx
编译安装Nginxlinux r语言安装,需要依赖pcre-devel和openssl-devel两个基础依赖包。所以在安装Nginx之前,需要先检查该依赖包是否已安装。
安装基础依赖包安装PCRE库
PCRE(opens new window)(Perl Compatible Regular Expressions)意为"Perl兼容正则表达式",安装PCRE是为了让Nginx支持具备URL重写功能的Rewrite模块,如果不安装,则Nginx无法使用Rewrite模块功能。
使用yum安装方式安装PCRE:
[root@edaa2f912abf /]# yum instal pcre pcre-devel -y
yum安装后检查安装结果:
[root@edaa2f912abf /]# rpm -qa pcre pcre-devel
pcre-8.32-17.el7.x86_64
pcre-devel-8.32-17.el7.x86_64
安装openssl-devel
使用yum安装openssl-devel:
[root@edaa2f912abf /]# yum install openssl openssl-devel -y
检查yum安装结果:
[root@edaa2f912abf /]# rpm -qa openssl openssl-devel
openssl-devel-1.0.2k-25.el7_9.x86_64

openssl-1.0.2k-25.el7_9.x86_64
安装Nginx
在确保Nginx编译安装所依赖的pcre-devel和openssl-devel已经安装好了后linux视频,可以下载Nginx源码进行编译安装。 Nginx源码可以从Nginx官方网站()找到相应版本源码的下载地址:
下载Nginx源码:
[root@edaa2f912abf /]# mkdir -p /home/tools/ && cd /home/tools
[root@edaa2f912abf tools]# wget -q http://nginx.org/download/nginx-1.16.0.tar.gz
[root@edaa2f912abf tools]# ls -lh
total 1012K

-rw-r--r-- 1 root root 1009K Apr 23 2019 nginx-1.16.0.tar.gz
添加nginx用户linux服务器系统,服务于Nginx:
[root@edaa2f912abf tools]# useradd nginx -u 1111 -s /sbin/nologin -M
解压软件包:
[root@edaa2f912abf tools]# tar xf nginx-1.16.0.tar.gz
编译Ngixn源码并安装:
[root@edaa2f912abf tools]# cd nginx-1.16.0
[root@edaa2f912abf nginx-1.16.0]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.16.0/ --with-http_stub_status_module --with-http_ssl_module
[root@edaa2f912abf nginx-1.16.0]# make
[root@edaa2f912abf nginx-1.16.0]# make install
其中--prefix选项就是配置安装的路径,如果不配置该选项,安装后可执行文件默认放在/usr/local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc,其它的资源文件放在/usr/local/share,各种文件比较分散。 为了便于集中管理某个软件的各种文件,可以配置–prefix,如: ./configure –-prefix=/application/nginx-1.16.0 可以把所有资源文件放在/application/nginx-1.16.0的路径中linux r语言安装,就不会分散了。 用了--prefix选项的另一个好处是卸载软件或移植软件,当某个安装的软件不再需要时,只须简单地删除该安装目录,就可以把软件卸载得干干净净;移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统)。
建立nginx应用程序软链接:
[root@edaa2f912abf nginx-1.16.0]# ln -s /application/nginx-1.16.0 /application/nginx
建立软件链接的操作并不是必须要做的,这样做的主要是为了后续nginx升级,用户操作不受影响。 对于普通用户,使用nginx的目录就是/application/nginx目录,不管后续如何升级Nginx版本,只需要将最新的Nginx版本目录与统一的/application/nginx目录建立新的软链接即可。
# 启动并检查安装结果
启动前为了避免报错,先检查配置文件语法:
[root@edaa2f912abf tools]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.16.0//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.16.0//conf/nginx.conf test is successful
启动Nginx服务:
[root@edaa2f912abf tools]# /application/nginx/sbin/nginx
查看Nginx服务是否启动成功:
[root@edaa2f912abf tools]# netstat -lntup|grpe nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3351/nginx: master
说明已经启动成功,打开浏览器输入就可以看到nginx网页信息。