Nginx编译安装

  1. 安装依赖
$ yum install -y gcc gcc-c++ gd gd-devel gperftools libxml2 libxslt-devel openssl openssl-devel pcre-devel perl-ExtUtils-Embed
  1. 创建用户
$ groupadd nginx
$ useradd -g nginx -s /sbin/nologin nginx
  1. 解压
$ tar xf nginx-1.20.2.tar.gz
  1. 编译&安装
$ cd nginx-1.20.2 && ./configure --prefix=/data/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module  --with-http_realip_module --with-stream_ssl_preread_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug 
$ make && make install
  1. 托管到systemd
$ vim /usr/lib/syste/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStartPre=/data/nginx/sbin/nginx -t
ExecStart=/data/nginx/sbin/nginx -c /data/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target
  1. 启动服务并设置开机自启
$ systemctl enable --now nginx.service
  1. 查看服务是否启动
$ systemctl status nginx

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