Linux Nginx安装以及可能出现错误

转载请标明出处 http://coderknock.com

安装过程

  1. http://nginx.org/download/nginx-1.9.15.tar.gz 下载nginx包(或者wget http://nginx.org/download/nginx-1.9.15.tar.gz直接在Linux上用命令下载)html

  2. 解压并转到目录下nginx

tar -zxvf nginx-1.9.15.tar.gz
cd nginx-1.9.15
  1. 设置一下配置信息 ./configure --prefix=/usr/local/nginx ,或者不执行此步,直接默认配置c++

  2. 编译安装ubuntu

make
make install

make的过程是把各类语言写的源码文件,变成可执行文件和各类库文件;
make install是把这些编译出来的可执行文件和库文件复制到合适的地方。浏览器

可能出现错误

  1. 在配置信息./configure --prefix=/usr/local/nginx 的时,出现错误:
/configure: error: the HTTP rewrite module requires the PCRE library.

解决方法:安装pcreui

yum -y install pcre pcre-devel

-y 是跳过全部须要手动确认的环节code

  1. 缺乏ssl错误,错误信息以下:
./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.

解决方法:安装opensslhtm

yum -y install openssl openssl-devel
  1. 缺乏编译器,错误信息以下:
./configure: error: C compiler cc is not found

解决方法:安装gcc-c++ip

yum -y install gcc-c++ autoconf automake

autoconf是自动配置,automake是自动编译md5

  1. 缺乏zlib包,错误信息以下:
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using –without-http_gzip_module
option, or install the zlib library into the system, or build the zlib
library
statically from the source with nginx by using –with-zlib=<path> option.

解决方法:安装zlib

yum install -y zlib-devel

安装完成后启动

安装成功后 /usr/local/nginx 目录下以下

fastcgi.conf            koi-win             nginx.conf.default
fastcgi.conf.default    logs                scgi_params
fastcgi_params          mime.types          scgi_params.default
fastcgi_params.default  mime.types.default  uwsgi_params
html                    nginx               uwsgi_params.default
koi-utf                 nginx.conf          win-utf

启动

确保系统的 80 端口没被其余程序占用,运行/usr/local/nginx/nginx 命令来启动 Nginx,

netstat -ano|grep 80

若是查不到结果后执行,有结果则忽略此步骤(ubuntu下必须用sudo启动,否则只能在前台运行)

sudo /usr/local/nginx/nginx

打开浏览器访问此机器的 IP,若是浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。

相关文章
相关标签/搜索