linux安装nginx,超详细步骤,100%成功

一.下载nginx,两种方式
1.官网下载:http://nginx.org/en/download.html

2.wegt下载

若wegt下载不成功,更改配置信息:

vim /etc/resolv.conf 
#resolv.conf中nameserver 更改为
nameserver 8.8.8.8
nameserver 8.8.8.4
wget http://nginx.org/download/nginx-1.16.1.tar.gz 

二、上传解压
1.我这里上传nginx-xxx.tar.gz至 /usr/local目录下

cd /
cd usr/local/
#解压
tar -zxvf nginx-xxx.tar.gz
#重命名
mv nginx-xxx nginx

2.检查nginx目录下是否有logs文件夹,没有则添加

mkdir logs

三、安装
1.先安装依赖

yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl-devel

若下载失败,请参考博客yum安装
https://blog.csdn.net/weixin_51414096/article/details/125927825

2.配置信息

#进入nginx目录
cd usr/local/nginx
#配置configure  --prefix 安装的路径 --with-http_ssl_module 安装ssl,--with-http_stub_status_module查看nginx的客户端状态
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module

3.编译安装

make & make install

四.启动
1.在nginx/sbin目录下操作

#启动
./nginx
#重启
./nginx -s reload
#关闭
./nginx -s stop
#查看nginx进程
ps -ef | grep nginx

2.若想在任何目录下操作,需配置路径

#进入/etc/profile 编辑
vim /etc/profile
#在末尾添加
PATH=$PATH:/usr/local/nginx/sbin
export PATH
#重启文件
source /etc/profile
/启动
nginx
/关闭
nginx -s stop
/重启
nginx -s reload

启动成功后访问 ip:端口(默认80)
linux安装nginx,超详细步骤,100%成功_第1张图片

你可能感兴趣的:(nginx,linux,运维)