源码安装Nginx并启动Nginx服务

1.  安装源码编译的工具:

yum install -y gcc gcc-c++ make

2.  安装 Nginx 所需的 pere 库:

yum install -y pcre-devel

3.  安装openssl-devel:

yum install -y openssl-devel

4.  下载nginx源码包并解压:

wget -c https://repo.huaweicloud.com/nginx/nginx-1.20.0.tar.gz

tar xf nginx-1.20.0.tar.gz -C /usr/local/src/

cd /usr/local/src/nginx-1.20.0/

5.  创建nginx用户和组:

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

6.  安装perl-ExtUtils-Embed:

yum install perl-ExtUtils-Embed -y

7.  执行configure文件

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx 
--with-threads --with-http_ssl_module --with-http_sub_module 
--with-http_gzip_static_module --with-http_auth_request_module 
--with-http_stub_status_module --with-http_perl_module --with-stream --with-pcre

8.  编译并安装nginx:

make && make install

9.  查看nginx的目录结构:

tree /usr/local/nginx/

/usr/local/nginx/
├── client_body_temp
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── html
│   ├── 50x.html
│   ├── index.html
├── logs 
├── sbin
    └── nginx

10.  nginx提供启动服务的脚本:

vim /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.conf
ExecStart=/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

11.  启动nginx服务:

systemctl start nginx.service

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值