nginx在linux中的安装配置

一、安装依赖(安装过的跳过)

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

   
   
  • 1

二、下载nginx稳定版

wget http://nginx.org/download/nginx-1.16.1.tar.gz 

   
   
  • 1

或者去nginx官网下载
在这里插入图片描述
下载完成后使用scp指令上传到服务器

scp 源文件地址 目标文件地址
# 示例
scp nginx-1.16.1.tar.gz root@120.xxx.xxx.232:/opt
# 上述示例,用户进入(cd)nginx下载存放到目录之后再操作

   
   
  • 1
  • 2
  • 3
  • 4

三、解压–编译–安装

  1. 解压
tar -zxvf nginx-1.16.1.tar.gz

   
   
  • 1
  1. 进入解压目录
cd nginx-1.16.1/

   
   
  • 1
  1. 编译
# 需要使用https执行指令
./configure  --with-http_ssl_module
# 不需要使用https执行
./configure 

   
   
  • 1
  • 2
  • 3
  • 4
  • 编译如果提示./configure: error: the HTTP rewrite module requires the PCRE library.,则执行yum -y install pcre-devel后重新编译
  • 提示./configure: error: the HTTP gzip module requires the zlib library.,则执行yum install -y zlib-devel后重新编译
  1. 安装
make && make install

   
   
  • 1

补充查看编辑参数

# 查看编译参数
./configure --help | more 

   
   
  • 1
  • 2

四、开放访问端口80(可自定义)

# 不同centos 系统指令有差别
/sbin/iptables -I INPUT  -p tcp --dport 80 -j ACCEPT

   
   
  • 1
  • 2

五、nginx服务的启动操作

启动
cd /usr/local/nginx/sbin
# 默认配置文件启动
./nginx

# 指定配置文件启动
./nginx -c /usr/local/nginx/conf/nginx.conf

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
停止
cd /usr/local/nginx/sbin
# 停止指令
./nginx -s stop

 
 
  • 1
  • 2
  • 3

六、开机启动nginx

编辑文件/etc/rc.d/rc.local在后面添加内容
vi /etc/rc.d/rc.local

 
 
  • 1

内容

/usr/local/nginx/sbin/nginx

 
 
  • 1

ll查看下rc.local文件,如果不是绿色表示没有执行权限,则执行指令chmod +x /etc/rc.d/rc.local

七、补充

查看帮助信息
cd /usr/local/nginx/sbin

./ngxin -h

  • 1
  • 2
  • 3

结果
在这里插入图片描述

查看安装时配置
cd /usr/local/nginx/sbin

./nginx -V

  • 1
  • 2
  • 3

结果
在这里插入图片描述

检查配置文件是否正确
cd /usr/local/nginx/sbin

./nginx -t

  • 1
  • 2
  • 3

结果
在这里插入图片描述

直接使用nginx指令,提示未找到命令

解决办法:

  1. 编辑/etc/profile文件vi /etc/profile在末尾处添加
PATH=$PATH:/usr/local/nginx/sbin
export PATH

 
 
  • 1
  • 2
  1. 执行source /etc/profile指令
配置

一般把配置放在/etc/nginx下面
1. 新建文件夹(用来存放nginx自定义配置文件)
shell mkdir -p /etc/nginx/conf.d
2. 在nginx的配置文件(默认/usr/local/nginx/conf/nginx.conf)中加入include /etc/nginx/conf.d/*.conf;
在这里插入图片描述
3. 修改完成记得nginx -s reload

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值