普通用户安装Nginx

简介:

一、安装前准备

安装包获取

Nginx网站http://nginx.org 下载软件版本包

目前主流版本为nginx-1.13.3   稳定版本为nginx-1.12.1,这里使用稳定版nginx-1.12.1 为例


1、安装pcre软件包

安装pcre库是为使Nginx支持HTTP rewrite模块

在Linux系统中查看pcre软件包是否已经安装,如果没有请事先安装好,在光盘里面可以使用rpm -ivh 安装

[root@iccsdb02 tmp]# rpm -qa | grep pcre

pcre-7.8-7.el6.x86_64


错误提示:./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.


解决办法:

yum -y install  pcre-devel-7.8-6.el6.x86_64


2、安装openssl-devel软件包

错误提示:./configure: error: the HTTP cache module requires md5 functions

from OpenSSL library.   You can either disable the module by using

--without-http-cache option, or install the OpenSSL library into the system,

or build the OpenSSL library statically from the source with nginx by using

--with-http_ssl_module --with-openssl=<path> options.


解决办法:

yum  -y install openssl openssl-devel


3、创建应用Nginx软件的应用用户

lvcreate  -L 1G -n lv_iccs apvg

mkfs.ext4 /dev/apvg/lv_iccs 

编辑/etc/fstab 里面实现自动挂载


4、创建应用用户

useradd  -u 601 -d /home/iccs iccs

chown iccs:iccs -R /home/iccs


5、解压软件包并赋权给应用用户

tar -xvf nginx-1.12.1.tar.gz

chown iccs:iccs -R /tmp/nginx-1.12.1


二、安装Nginx软件

1、使用configure 命令可以检测软件的安装环境,并生成Makefile文件

su - iccs

cd /tmp/nginx-1.12.1


./configure\

> --user=iccs \

> --group=iccs \

> --prefix=/home/iccs \

> --sbin-path=/home/iccs/sbin/nginx \

> --conf-path=/home/iccs/conf/nginx.conf \

> --error-log-path=/home/iccs/log/error.log \

> --http-log-path=/home/iccs/log/access.log \

> --http-client-body-temp-path=/home/iccs/tmp/client_body \

> --http-proxy-temp-path=/home/iccs/tmp/proxy \

> --http-fastcgi-temp-path=/home/iccs/tmp/fastcgi \

> --pid-path=/home/iccs/var/run/nginx.pid \

> --lock-path=/home/iccs/var/lock/subsys/nginx \

> --with-http_stub_status_module \

> --with-http_ssl_module \

> --with-http_gzip_static_module 


备注:

configure 选项                                    【选项含义】

--user                                            指定启动程序所属用户

--group                                            指定启动程序所属组

--prefix                                              指定nginx安装路径

--sbin-path                                    设置nginx二进制文件的路径

--conf-path                                    指定配置文件的路径

--error-log-path                            指定错误日志文件路径

--http-log-path                            指定访问日志文件路径

--http-client-body-temp-path    设置存储HTTP客户端请求主体的临时文件路径

--http-proxy-temp-path                    设置存储HTTP代理临时文件的路径

--pid-path                                    设置nginx.pid文件路径

--lock-path                                    设置nginx.lock 文件路径

--with-openssl                            启用SSL

--with-pcre                                    启用正规表达式

--with-http_stub_status_module      安装可以监控nginx状态的模块

--with-http_ssl_module                    启用SSL支持

--with-http_gzip_static_module    启用gzip压缩


2、开始安装

[iccs@iccsdb02 nginx-1.12.1]$ make 

[iccs@iccsdb02 nginx-1.12.1]$ make install


三、启动Nginx 

[iccs@iccsdb02 sbin]$ ./nginx 

nginx: [emerg] mkdir() "/home/iccs/tmp/client_body" failed (2: No such file or directory)

nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

备注:这里启动的时候遇到两个错误

1、因为在目录下面没有找到tmp目录,所以无法写入缓存文件

2、因为我们是应用用户安装并且启动的,在Linux系统下普通用户是不能使用1024以下端口的,而Nginx默认是80端口,所以需要修改/home/iccs/conf/nginx.conf配置文件将端口改为1024以上,我这里改为了1983

3、如果你是root安装的话,在启动nginx之前,也一定要确保停止其它web服务如Apache等服务冲突防止端口


5、查看nginx进程和端口, 和之前配置文件worker process 一共8个,和配置文件中一样

这里我在修改端口的时候将worker process改为了5 默认为1,如下结果可以看出我们已经启动成功了 wKioL1lwCrmQeh03AAC_vYx0v4A475.jpg


wKiom1lwCz-xJg4qAACKIN51xYc979.jpg

6、Nginx 启动常用选项

Nginx       [选项]

-p          <前缀>设置前缀路径,默认为/opt/nginx

-c          <文件名>设置配置文件,默认为/etc/nginx/nginx.conf

-v        显示版本信息并退出

-V        显示版本信息和配置选项,然后退出

-t        测试配置时候正确,并退出

-q        配置测试过程中抑制非错误信息

-s          <信号>将stop、quit、reopen、reload等信号发送给nginx主进程

直接启动服务执行 /home/iccs/sbin/nginx 


为了方便加入一下应用用户的环境变量

vim /home/icccs/.bash_profile 将命令路径变成如下

PATH=$PATH:$HOME/bin:$HOME/sbin




本文转自 yuri_cto 51CTO博客,原文链接:http://blog.51cto.com/laobaiv1/1949037,如需转载请自行联系原作者

相关文章
|
1月前
|
应用服务中间件 nginx
Nginx安装nginx-rtmp-module模块
【2月更文挑战第4天】 nginx中的模块虽然就是类似插件的概念,但是它无法像VsCode那样轻松的安装扩展。 nginx要安装其它模块必须同时拿到nginx源代码和模块源代码,然后手动编译,将模块打到nginx中,最终生成一个名为nginx的可执行文件。
75 6
|
1天前
|
负载均衡 前端开发 应用服务中间件
Nginx安装与使用
Nginx安装与使用
|
1天前
|
负载均衡 Java 应用服务中间件
nginx安装在linux上
nginx安装在linux上
19 2
|
8天前
|
应用服务中间件 nginx
yum 安装报错 No package nginx available Error:Nothing to do
yum 安装报错 No package nginx available Error:Nothing to do
22 1
|
28天前
|
应用服务中间件 Linux PHP
Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux下安装php环境并且配置Nginx支持php-fpm模块
29 0
|
29天前
|
前端开发 应用服务中间件 网络安全
http转为https,ssl证书安装及nginx配置
http转为https,ssl证书安装及nginx配置
47 1
|
29天前
|
网络协议 应用服务中间件 网络安全
linxu安装nginx
linxu安装nginx
69 0
|
1月前
|
NoSQL 关系型数据库 MySQL
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
221 0
|
1月前
|
负载均衡 应用服务中间件 nginx
|
1月前
|
应用服务中间件 nginx Windows
windows下快速安装nginx 并配置开机自启动
windows下快速安装nginx 并配置开机自启动
windows下快速安装nginx 并配置开机自启动