通过xshell在linux上安装nginx1.12.0

通过xshell在linux上安装nginx1.12.0

0)环境安装

Nginx是C语言开发,建议在 Linux 上运行,当然,也可以安装Windows版本,本篇则使用CentOS 7作为安装环境。

gcc安装:安装 nginx 需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,则需要安装:

yum install gcc-c++

PCRE pcre-devel安装:PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括perl兼容的正则表达式库。Nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库,pcre-devel 是使用pcre开发的一个二次开发库。Nginx也需要此库。命令:

yum install -y pcre pcre-devel

zlib安装:zlib库提供了很多种压缩和解压缩的方式, Nginx使用zlib对http包的内容进行gzip ,所以需要在Centos上安装zlib库。

yum install -y zlib zlib-devel

OpenSSL安装:OpenSSL是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。Nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在Centos安装OpenSSL库。

yum install -y openssl openssl-devel

1)下载安装

方式一:直接下载 .tar.gz 安装包,地址:https://nginx.org/en/download.html

img

方式二:使用wget命令下载(推荐)。确保系统已经安装了wget,如果没有安装,执行 yum install wget 安装。

wget -c https://nginx.org/download/nginx-1.12.0.tar.gz

img

我下载的是1.12.0版本,这个是目前的稳定版。解压命令:

tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0

2)配置编译

其实在 nginx-1.12.0 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。

方式一:使用默认配置

./configure

方式二:自定义配置(不推荐)

./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

注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录

编译安装

make
make install 
或 make install PREFIX=/usr/nginx #这里可以指定安装位置

查找安装路径:

whereis nginx

img

3)启动nginx

cd /usr/local/nginx/sbin/ #进入bin目录
./nginx #启动
./nginx -s stop #此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程
./nginx -s quit #此方式停止步骤是待nginx进程处理任务完毕进行停止
./nginx -s reload #刷新

启动成功后,在浏览器可以看到这样的页面:

img

posted @ 2020-05-24 15:22  肖德子裕  阅读(3168)  评论(0编辑  收藏  举报