LINUX安装NGINX

Linux版本: CentOS 6.5 64位

一. 安装编译工具及库文件

# yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

二. 安装PCRE,让NGINX支持Rewrite功能

# yum install pcre

三. 安装NGINX

- 3.1 下载NGINX

可在http://nginx.org/en/download.html下载最新版本的NGINX

# wget http://nginx.org/download/nginx-1.13.7.tar.gz

- 3.2 解压

# tar -zxvf nginx-1.13.7.tar.gz

- 3.3 进入安装包目录

# cd nginx-1.13.7

- 3.4 编译安装

# ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module && make && make install && make clean
--with-pcre=/usr/src/pcre-8.21 指的是pcre-8.21 的源码路径。
--with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源码路径。

- 3.5 查看安装路径并进入

[root@localhost nginx-1.13.7]# whereis nginx
nginx: /usr/local/nginx [root@localhost nginx-1.13.7]# cd /usr/local/nginx

- 3.6 启动NGINX

[root@localhost nginx]# sbin/nginx

启动后可在浏览器上访问 host:port,如 127.0.0.1:80 。若打开后出现如下页面则安装完成 
安装完成

四. 安装过程中遇到的问题

- 4.1 使用make编译时报错

提示信息:

在包含自 src/core/ngx_core.h:71 的文件中,
                 从 src/core/nginx.c:9:
src/core/ngx_regex.h:15:18: 错误:pcre.h:没有那个文件或目录 In file included from src/core/ngx_core.h:71, from src/core/nginx.c:9: src/core/ngx_regex.h:24: 错误:expected specifier-qualifier-list before ‘pcre’

原因及解决方法: 
未安装pcre-devel

# yum install pcre-devel

yum -y install openssl openssl-devel

更改后再次运行出错,提示信息:

cd /srv/pcre2-10.21 \
        && make libpcre.la
make[2]: Entering directory `/srv/pcre2-10.21'
make[2]: *** 没有规则可以创建目标“libpcre.la”。 停止。
make[2]: Leaving directory `/srv/pcre2-10.21'
make[1]: *** [/srv/pcre2-10.21/.libs/libpcre.a] 错误 2
make[1]: Leaving directory `/srv/nginx-1.13.7'

原因及解决方法: 
将pcre安装成了pcre2,NGINX不支持pcre2,换成pcre

- 4.2 启动NGINX失败

提示信息:

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] still could not bind()

原因及解决方法: 
NGINX所使用的端口号被占用,默认端口为80,可以在配置文件中修改或者关闭占用端口的进程

NGINX配置文件如下:

[root@localhost conf]# vi nginx.conf

#user  nobody;
worker_processes  1;

#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; "nginx.conf" 117L, 2656C written

转载于:https://www.cnblogs.com/liushuchen/p/9274256.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值