Linux下安装nginx教程

一:先检查是否安装nginx

rpm -qa |grep nginx

二:检查没有安装nginx后,下载安装nginx的前置软件,这里用yum命令安装

2.1 安装 Nginx 的编译环境 gcc

yum install gcc-c++

2.2 安装 pcre pcre-devel (nginx  http 模块使用 pcre 解析正则表达式,所以安装 perl 兼容的正则表达式库)

yum install -y pcre pcre-devel

2.3 安装 zlib (nginx 使用 zlib  http 包的内容进行 gzip)

yum install -y zlib zlib-devel

2.4 安装 Open SSL (nginx 不仅支持 http 协议,还支持 https(即在 ssl 协议上传输 http),如果使用了 https ,需要安装 OpenSSL 库)

yum install -y openssl openssl-devel

三:官网下载nginx安装包并解压

nginx官网

这里我下载的是1.10.1版本,上传至opt目录下,进行解压。然后进入解压目录

tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1

四:配置与安装

4.1.1 使用默认配置

./configure

4.1.2 自定义配置

./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

这里我们选择默认配置

4.2 编译安装

make && make install

4.3 安装完后可以查找安装路径

whereis nginx

五:配置环境变量

编辑profile文件,在里面添加环境变量,然后重新编译profile文件

vim /etc/profile

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

source /etc/profile

六:nginx的指令

启动nginx:/usr/local/nginx/sbin/nginx

启动后打开浏览器访问会得到nginx的欢迎页,就成功了

以下是nginx的其他指令

nginx -s stop 停止nginx,此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
nginx -s quit 停止nginx,此方式停止步骤是待nginx进程处理任务完毕进行停止。
nginx -s reload 重启nginx,一般是重新载入配置文件时使用
nginx -s reopen 重启nginx,重新打开日志文件
nginx -v 查看nginx版本
nginx -t 查看配置文件正确性

七:设置开机自启动

vi /etc/rc.local
添加:/usr/local/nginx/sbin/nginx

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值