Centos7 编译安装Nginx

nginx版本分开发版和稳定版,生产环境使用稳定版,实验新功能,新特性可以使用开发版。

安装nginx编译需要依赖的包:

yum install gcc gcc-c++ wget

yum install pcre-devel zlib-devel openssl-devel

说明:

zlib:nginx提供gzip模块,需要zlib库支持

        openssl:nginx提供ssl功能

        pcre:让nginx支持地址重写rewrite功能

建立用户组

        groupadd -r nginx

添加一个用户

        useradd -s /sbin/nologin -g nginx -r nginx

下载源码包:

cd /usr/local/src

wget https://nginx.org/download/nginx-1.14.0.tar.gz

tar zxvf nginx-1.14.0.tar.gz

cd nginx-1.14.0

可以通过参数 --help来查看编译参数

./configure --help

根据自己的需要配置编译参数:

./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_realip_module \
--with-http_ssl_module

make && make install

添加环境变量:

vim /etc/profile

文件末尾追加:

PATH=$PATH:'/usr/local/nginx/sbin/'

保存退出后,执行

source /etc/profile

查看nginx版本:

    nginx -v 

查看编译参数:

    nginx -V

启动命令:

     nginx 

停止命令:

    nginx -s stop

配置文件:

/usr/local/nginx/conf/nginx.conf

测试访问:

       wget localhost

如果能下载到index.html 就表明nginx安装配置成功。

相关网址:

nginx官网: http://nginx.org

nginx下载链接:         http://nginx.org/en/download.html

nginx二进制包:         http://nginx.org/en/linux_packages.html#stable

nginx中文手册:         https://cloud.tencent.com/developer/doc/1158

nginx相关书籍: http://tengine.taobao.org/book/

猜你喜欢

转载自blog.csdn.net/mrtwenty/article/details/80493929