linux配置nginx详解

下载安装包

nginx官方下载地址
在这里插入图片描述

上传至linux对应文件夹

先上传至/usr/local,cd进压缩包所在的对应的目录,在这里解压,运行命令

cd /usr/local/
tar -zxvf nginx-1.20.1.tar.gz #文件名根据你自己的压缩包文件名来

make

将解压好的文件夹重命名为nginx,进入,依次执行

cd /usr/local/nginx
./configure
make
make install
mkdir logs

如果make执行报错make: *** No rule to make target 'build', needed by 'default'. Stop.

重新解压并在之前加两步。

yum update
yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd-devel
cd /usr/local/nginx
./configure
make
make install
mkdir logs

安装服务

进入/etc/systemd/system,找到nginx.service

1.如果没有找到对应文件,则直接启动

cd usr/local/nginx/sbin
./nginx

2.如果找到了,进行修改:

在这里插入图片描述
内容在这,注意内容中包含路径,如果你的路径不跟我完全一致自行修改

[UNIT]

Deion=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/kill -s HUP $MAINPID

ExecStop=/bin/kill -s TERM $MAINPID

[Install]

WantedBy=multi-user.target

运行启动

systemctl enable nginx

失败也没关系,重启一下远程服务器试试

加环境变量

在这里插入图片描述
去linux主目录在profile下面加一行就行,记得地址改自己的

export PATH=$PATH:/usr/local/nginx/sbin 

去命令行执行让它生效

source /etc/profile

nginx常用命令

关闭

nginx -s stop

重启

nginx -s reload

配置文件

nginx -c 路径/nginx.conf
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

在下月亮有何贵干

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值