Linux 安装 Nginx

首先 下载Nginx 上传到/apps/svr
image

cd /apps/svr
tar -zxvf nginx.tar.gz
yum -y install gcc gcc-c++ autoconf automake make

# PCRE库支持正则表达式。如果我们在配置文件nginx.conf中使用了正则表达式,那么在编译Nginx时就必须把PCRE库编译进Nginx,因为Nginx的HTTP模块需要靠它来解析正则表达式。
cd /apps/svr/pcre-8.35
./configure
make && make install
pcre-config --version


cd /apps/svr/nginx-1.21.6/
yum install openssl openssl-devel  -y
./configure --with-http_stub_status_module --with-http_ssl_module
make && make install

安装成功啦!注意,这里如果你是root用户,nginx并不在当前的nginx文件夹,而是在/usr/local/nginx

设置开机自启

cd /lib/systemd/system
vim nginx.service

增加以下内容:

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /usr/local/nginx/logs/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /usr/local/nginx/logs/nginx.pid)"

[Install]
WantedBy=multi-user.target
# 查看服务状态
systemctl status nginx.service

# 开机自启动
systemctl enable nginx.service

# 关闭开机自启
systemctl disable nginx.service
posted @ 2022-06-21 23:57  快乐的海盗  阅读(23)  评论(0编辑  收藏  举报