nginx(1)linux系统安装nginx

来源:互联网 发布:微念科技有限公司 知乎 编辑:程序博客网 时间:2024/05/19 14:38

一 官网下载nginx

官网地址: http://nginx.org

二 安装gcc编译器

命令: yum install gcc

安装需保持连网状态,如已经安装过,跳过此步,以下命令遵循此原则。

三 安装make命令

命令: yum install make

四 安装pcre

命令: yum install pcre*

安装该命令主要是为了支持rewrite功能。

五 安装openssl

命令: yum install openssl*

如果需要ssl支持,否则,可以跳过此步

六 nginx配置

cd到nginx所在目录,例如ngnix/usr/local/nginx-1.12.0,然后执行如下命令

./configure --prefix=/usr/local/nginx-1.12.0 --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre

配置含义:

--with-http_ssl_module: 支持https

--with-http_v2_module:需通过ssl支持

--with-http_stub_status_module:支持nginx状态查询

--with-pcre: 支持rewrite功能,定制pcre

七 编译

make

八 安装

make install

九 启动

/usr/local/nginx-1.12.0/sbin/nginx

如果启动时报如下错误:

nginx: [alert] could not open error log file: open() "/usr/local/nginx-1.12.0/logs/error.log" failed (2: No such file or directory)
2017/05/01 01:00:19 [emerg] 5329#0: open() "/usr/local/nginx-1.12.0/logs/access.log" failed (2: No such file or directory)

先在/usr/local/nginx-1.12.0/下创建一个logs文件夹,然后再文件夹下创建error.log,access.log文件,先让我们的nginx起来。

查看ps -ef|grep nginx查看nginx是否启动:

[root@lanhuigu nginx-1.12.0]# ps -ef|grep nginx
root      5462     1  0 01:23 ?        00:00:00 nginx: master process /usr/local/nginx-1.12.0/sbin/nginx
nobody    5463  5462  0 01:23 ?        00:00:00 nginx: worker process             
root      5472  2312  0 01:25 pts/0    00:00:00 grep nginx

十 关闭

/usr/local/nginx-1.12.0/sbin/nginx -s stop

十一 重置

/usr/local/nginx-1.12.0/sbin/nginx -s reload

如果ngnix配置有修改,通过如下命令重新加载即可

0 0