Nginx教程

nginx安装

本文主要是介绍nginx安装,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
  1. 下载nginx
  2. 下载依赖
yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel pcre pcre-devel
  1. 将下载好的nginx上传至服务器
  2. 解压,编译,安装
# 解压
tar zxvf nginx-1.21.6.tar.gz
# 进入nginx安装包
cd nginx-1.21.6
# 源码安装,自定义安装位置
./configure --prefix=/usr/local/nginx
# 编译安装
make
make install
  1. 安装成系统服务
vi /usr/local/systemd/system/nginx.service

#脚本内容
[Unit]
Description=nginx - web server
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=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
wantedBy=multi-user.target
  1. 重新加载系统服务
systemctl daemon-reload
  1. 基本命令
# 开机自启
systemctl enable nginx

# 启动
systemctl start nginx

# 重新启动
systemctl restart nginx

# 关闭
systemctl stop nginx

# 查看运行状态
systemctl status nginx
这篇关于nginx安装的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!