Fork me on GitHub

编译安装NGINX-1.21.0

官网:http://nginx.org/en/download.html

下载地址:http://nginx.org/download/nginx-1.21.0.tar.gz

一、编译前提,需要安装必要的包

yum install gcc pcre-devel openssl-devel zlib-devel  wget -y

(wget不是编译必须的,只是我后面要下载东西用,就一起安装)

二、下载对应的NGINX包

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

三、创建nginx用户

useradd -r -s /sbin/nologin nginx

四、解压nginx到/data/下

tar xf /root/nginx-1.21.0.tar.gz -C /data/

(路径自定义)

五、进入解压的nginx目录中

cd /data/nginx-1.21.0/

六、编译安装

复制代码
./configure --prefix=/apps/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
复制代码

计划安装的路径在/apps/

七、开始编译

make -j 8 && make install

-j 8 表示CPU八核,可以按照实际CPU核数定义,越多越快

八、为了方便启动可以创建软链接或者修改PATH变量

ln -s /apps/nginx/sbin/nginx /usr/sbin/

九、开启nginx服务

nginx

十、测试访问

[09:34:18 root@localhost nginx-1.21.0]#curl 192.168.1.7
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

十一、设置为开机自启动

  1、修改centos7自带的开机自启动文件中

vim  /etc/rc.d/rc.local

  2、添加NGINX的路径

/usr/sbin/nginx

  3、这个文件默认没有执行权限,添加执行权限

chmod +x /etc/rc.d/rc.local

十二、NGINX 的其他命令点击此处查看

 注释:执行./configure 会检查当前环境是否满足编译要求,检查当前的环境,并且生成makefile,这个Makefile就是编译的时候使用的,make install 把生成的模块拷贝到相应的目录。

 

posted @ 2021-05-28 09:36  Alex-Lzy  阅读(2069)  评论(0编辑  收藏  举报