安装nginx
编译安装nginx
yum install pcre pcre-devel openssl-devel libxml2-devel libxslt-devel gd-devel perl-ExtUtils-Embed gperftools gperftools-devel gcc -y
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -xf nginx-1.20.1.tar.gz -C /usr/local/
useradd -u 1111 -s /sbin/nologin www -M
cd /usr/local/nginx-1.20.1/
./configure --user=www --group=www --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module --with-pcre #如果还有想要加载的模块,可以根据实际情况继续添加
make && make install
cd /usr/local/nginx
./sbin/nginx
netstat -lntup |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 29600/nginx: master
配置systemd管理nginx:
cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start nginx
systemctl enable nginx
systemctl status nginx
安装nginx(yum最新版本)
yum install -y yum-plugin-priorities #安装这个插件,给官方源提权
cat /etc/yum.repos.d/nginx.repo
[nginx]
name = nginx repo
baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck = 0
enabled = 1
priority=1 ##增加优先参数,使得官方源优先epel源。
yum install nginx -y
systemctl start nginx
systemctl enable nginx
systemctl status nginx