在linux系统上安装Nginx

来源:互联网 发布:阿里云服务器搭建免流 编辑:程序博客网 时间:2024/06/06 19:23

1.开始安装Nginx

在正式开始前,编译环境gcc g++开发库之类的需要提前安装好,这里默认你已经安装好。

Ubuntu平台环境可以使用以下指:(这种平台本人未测试)
apt-get install build-essential
apt-get install libtool

2. Centos平台编译环境使用如下指令:

安装make (注意:这里需要yum库,不会的看我另外一篇博客,制作本地yum源)
yum -y install gcc automake autoconf libtool make

3.安装g++

yum install gcc gcc-c++

4.Nginx依赖以下模块:

gzip模块需要zlib库
rewrite模块需要pcre库
ssl功能需要openssl库

一般我们需要先安装pcre,zlib,前者为了重写rewrite,后者为了gzip压缩。

5.安装openssl

选定源码目录,选定/usr/local/src
下载openssl,地址:ftp://ftp.openssl.org/source/
tar -zxvf openssl-1.0.1c.tar.gz (下载稳定版本)
cd openssl-1.0.1c
./config && make && make install

6.安装pcre

tar zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure && make && make install

7.安装zlib库

tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install

8.安装nginx.

Nginx一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中的一个,下面是把Nginx安装到/usr/local/nginx目录的详细步骤如下:

tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
mkdir /usr/local/nginx

groupadd -r nginx
useradd -r -g nginx -s /bin/false -M nginx

注意 \ 前面至少一个有空格

[root@localhost src]# cd nginx-1.8.0
[root@localhost nginx-1.8.0]# groupadd -r nginx
[root@localhost nginx-1.8.0]# useradd -r -g nginx -s /bin/false -M nginx

注意:下面的with后面的路径一定要正确,否则会安装失败

[root@localhost nginx-1.8.0]# ./configure –sbin-path=/usr/local/nginx/nginx \

–conf-path=/usr/local/nginx/nginx.conf \
–pid-path=/usr/local/nginx/nginx.pid \
–with-http_ssl_module \
–with-pcre=../pcre-8.37 \ #指向解压的源码目录(这里的../可以写成绝对路径,就是你刚刚安装的路径)
–with-zlib=../zlib-1.2.8 \ #指向解压的源码目录(这里的../可以写成绝对路径)
–with-openssl=../openssl-1.0.1c \ #指向解压的源码目录(这里的../可以写成绝对路径)
–with-http_stub_status_module \
–user=nginx \
–group=nginx;

make && make install

在此过程中还可以使用下面的模块:

–with-http_gzip_static_module \
–with-http_mp4_module \
–with-http_flv_module \

安装后的现象:
进入/usr/local/nginx,发现有如下内容:
这里写图片描述

9.启动nginx

/usr/local/nginx/nginx #不指定配置文件地址
/usr/local/nginx/nginx -c /usr/local/nginx/nginx.conf #指定配置文件地址

若此过程中出现了如下错误:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
使用命令关闭占用80端口的程序
sudo fuser -k 80/tcp

10.停止服务:

kill cat /usr/local/nginx/nginx.pid

在浏览器中输入:192.168.6.25(如果是本机输入localhost)如果看到欢迎界面则安装成功:
这里写图片描述

原创粉丝点击