nginx安装

1、下载源码
wget https://nginx.org/download/nginx-1.11.3.tar.gz
tar -zxvf nginx-1.11.3.tar.gz
cd nginx-1.11.3

2、./configure
报错了:

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

上面提示我们说如果需要开启http rewrite功能,那就必须依赖PCRE扩展,我们知道rewrite在web开发中是非常重要的。安装之…

找到源码下载之:

wget http://ftp.exim.llorien.org/pcre/pcre2-10.22.tar.gz
tar -zxvf pcre2-10.22.tar.gz
cd pcre2-10.22/
./configure
make
make install

再继续安装nginx:

./configure –with-pcre=/home/local/pcre2-10.22/

发现执行完上面的配置命令后看到下面的配置汇总信息,貌似是openssl和zlib扩展不是必须安装的,但是为了完整性(装逼),还是装一下吧。

Configuration summary
  + using PCRE library: /home/local/pcre2-10.22/
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

安装openssl:

wget https://www.openssl.org/source/openssl-1.0.2h.tar.gz
tar -zxvf openssl-1.0.2h.tar.gz
./config 
make depend
make & make install

安装zlib:

wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make & make install

最后安装nginx:

./configure --with-pcre=/home/local/pcre2-10.22 --with-openssl=/home/local/openssl-1.0.2h --with-zlib=/home/local/zlib-1.2.8 --prefix=/home/local/nginx

这里报了一个错误:

In file included from src/core/ngx_core.h:72:0,
                 from src/core/nginx.c:9:
src/core/ngx_regex.h:15:18: fatal error: pcre.h: No such file or directory
 #include 
                  ^
compilation terminated.
make[1]: *** [objs/src/core/nginx.o] Error 1
make[1]: Leaving directory `/home/local/nginx-1.11.3'
make: *** [build] Error 2

网上搜了一下是因为没有安装pcre-devel库,so,安装之。
yum install pcre-devel.*

再次
make clean
make & make install

草,这时候又报了个错:

cd /home/local/pcre2-10.22 \
&& make libpcre.la
make[2]: Entering directory `/home/local/pcre2-10.22'
make[2]: *** No rule to make target `libpcre.la'.  Stop.
make[2]: Leaving directory `/home/local/pcre2-10.22'
make[1]: *** [/home/local/pcre2-10.22/.libs/libpcre.a] Error 2
make[1]: Leaving directory `/home/local/nginx-1.11.3'
make: *** [install] Error 2

搜了一大堆也没找到,干脆换个低版本的试试(我的是pcre-8.31 wget http://exim.mirror.fr/pcre/pcre-8.31.tar.gz),果然好用。

先测试一下nginx是否能启动:
sbin/nginx

注:
mac的话会报一个错误:nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
主要原因是由于在Linux中1024以下的端口号都需要root权限才能使用,所以普通用户启动程序绑定会报出权限问题。
解决办法是在命令前边加sudo

netstat -tunpl |grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6224/nginx: master

最后在防火墙开启一下80端口别人才能访问:

# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
# firewall-cmd --list-all
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 80/tcp
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 

# iptables -L -n | grep 80          
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80 ctstate NEW

好了,nginx基本配好了。

此条目发表在 nginx 分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*


*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>