Linux源码编译安装nginx

13 篇文章 0 订阅

一、安装所需环境:

    yum -y install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel 

二、下载及安装nginx

1.下载nginx:wget http://nginx.org/download/nginx-1.8.1.tar.gz

2.解压nginx: tar -xzf nginx-1.8.1.tar.gz

3.添加用户组:groupadd www、useradd -g www www

3.编译nginx:进入解压之后的目录执行 (这里prefix为安装目录)

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

4.安装nginx:make && make install

(安装完成之后:make[1]: Leaving directory `/usr/local/nginx-1.8.1')  无伤大雅

5.验证是否安装成功:/usr/local/nginx/sbin/nginx -V

输出:

nginx version: nginx/1.8.1

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

built with OpenSSL 1.0.2k-fips  26 Jan 2017

TLS SNI support enabled

configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-threads

三、配置nginx

vi /usr/lib/systemd/system/nginx.service

添加如下:

[Unit]

Description=nginx - high performance web server

Documentation=http://nginx.org/en/docs/

After=network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

PIDFile=/usr/local/nginx/logs/nginx.pid

ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.confExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true [Install]WantedBy=multi-user.target

执行:

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

启动nginx:

systemctl start nginx

设置开机启动:

systemctl enable nginx

tar -zxf nginx-1.18.0.tar.gz

./configure  --prefix=/data/dc/nginx

make && make install

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值