源码安装nginx并提供服务脚本

一、下载nginx

①官网复制下载链接

源码安装nginx并提供服务脚本_第1张图片

②在Linux中下载

[root@openEuler2 ~]# wget -c https://nginx.org/download/nginx-1.24.0.tar.gz

二、解压并指定路径

[root@openEuler2 ~]# tar xf nginx-1.24.0.tar.gz -C /usr/local/src/

三、安装依赖

dnf install -y gcc gcc-c++ make pcre-devel openssl-devel

四、./configure 

[root@openEuler2 ~]# mkdir -p /var/log/nginx/
[root@openEuler2 nginx-1.24.0]# ./configure --prefix=/usr/local/nginx  \
> --sbin-path=/usr/sbin/nginx \
> --http-log-path=/var/log/nginx/access.log \
> --error-log-path=/var/log/nginx/error.log \
> --pid-path=/var/run/nginx.pid

源码安装nginx并提供服务脚本_第2张图片

五、编译与安装 

[root@openEuler2 nginx-1.24.0]# make
[root@openEuler2 nginx-1.24.0]# make install

六、服务脚本 

[root@openEuler2 nginx-1.24.0]# vim  more /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=mixed
PrivateTmp=true

[Install]
WantedBy=multi-user.target

七、测试 

源码安装nginx并提供服务脚本_第3张图片

你可能感兴趣的:(nginx,服务器,运维)