美文网首页
Nginx源码安装

Nginx源码安装

作者: snowstorm | 来源:发表于2018-02-05 10:20 被阅读0次

本次安装使用系统CentOS Linux release 7.2.1511 (Core)

1.更新系统软件

$yum update

2.安装make

$yum -y install gcc automake autoconf lib tool make

3.安装g++

$yum install gcc gcc-c++

4.选定源码目录

##本次选定的源码目录是这个
/usr/local/src

5.安装前置依赖pcre、lib和ssl

以下是安装过程,按照顺序执行命令即可

##下载安装pcre库
1.$wget http://exim.mirror.fr/pcre/pcre-8.37.tar.gz
2.$tar -zxvf pcre-8.37.tar.gz
3.$cd pcre-8.37/
4.$./configure
5.$make
6.$make install
##安装lib库
1.$wget http://zlib.net/fossils/zlib-1.2.10.tar.gz
2.$tar -zxvf zlib-1.2.10.tar.gz
3.$cd zlib-1.2.10
4.$./configure
5.$make
6.$make install
##安装ssl
1.$wget http://distfiles.macports.org/openssl/openssl-1.0.2n.tar.gz
2.$tar -zxvf openssl-1.0.2n.tar.gz
3.$./config
4.$make
5.$make install
##查看当前openssl版本
6.$openssl version
##替换老版本
7.$mv /usr/bin/openssl /root/
8.$ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl

6.安装nginx

以nginx-1.8.0为例

1.$wget http://nginx.org/download/nginx-1.8.0.tar.gz
2.$tar -zxvf nginx-1.8.0.tar.gz
3.$mkdir nginx
4.$mv nginx-1.8.0 nginx
5.$cd nginx/nginx-1.8.0/
6.$./configure --prefix=/home/test/nginx  \
--sbin-path=/home/test/nginx/sbin/nginx \
--conf-path=/home/test/nginx/conf/nginx.conf \
--error-log-path=/home/test/nginx/logs/error.log  \
--http-log-path=/home/test/nginx/logs/access.log  \
--pid-path=/home/test/nginx/var/run/nginx.pid \
--lock-path=/home/test/nginx/var/lock/nginx.lock  \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/home/test/nginx/var/client/ \
--http-proxy-temp-path=/home/test/nginx/var/proxy/ \
--http-fastcgi-temp-path=/home/test/nginx/var/fcgi/ \
--http-uwsgi-temp-path=/home/test/nginx/var/uwsgi \
--http-scgi-temp-path=/home/test/nginx/var/scgi \
--with-pcre=/usr/local/src/pcre-8.37 \
--with-zlib=/usr/local/src/zlib-1.2.10

7.$make
8.$make install

安装成功后的nginx目录如下:

[root@optimus nginx]# ls
conf  html  logs  nginx-1.8.0  sbin  var

启动nginx

[root@optimus sbin]# ./nginx
nginx: [emerg] getpwnam("nginx") failed

原因:系统没有安装nginx用户导致

解决:

1.$useradd -s /sbin/nologin -M nginx
2.$id nginx

启动:

1.$./nginx
2.$ ps -ef | grep nginx
root    38222    1  0 10:02 ?        00:00:00 nginx: master process ./nginx
nginx    38223 38222  0 10:02 ?        00:00:00 nginx: worker process
root    38225 38168  0 10:02 pts/0    00:00:00 grep --color=auto nginx

浏览器访问ip地址结果如下表示正常:

20180205101133.png

注意:

  1. nginx.conf中用户user需要对操作的目录有读写权限

附nginx常用命令:

  1. 启动 ./nginx
  2. 检查配置正确与否 ./nginx -t
  3. 热加载配置 ./nginx -s reload
  4. 快速关闭nginx ./nginx -s stop
  5. 优雅的关闭nginx ./nginx -s quit

相关文章

网友评论

      本文标题:Nginx源码安装

      本文链接:https://www.haomeiwen.com/subject/objbzxtx.html