Nginx安装?开箱即用?

2018-06-29  本文已影响0人  tobrainto

官网

http://nginx.org/
下载:http://nginx.org/download/

Nginx版本类型

Nginx官网提供了三个类型的版本
Mainline version:Mainline是Nginx目前主力在做的版本,开发版
Stable version:最新稳定版,生产环境上建议使用的版本
Legacy versions:遗留的老的稳定版
我们安装的时候注意在官网选择安装Stable的版本
这里我们选择的是nginx-1.12.2

环境

CentOS 6.5 x64
#设置hostname
master 192.168.40.130

安装方式

源码编译安装

安装依赖类库

c++ nginx的编译依赖
prce 重定向支持
openssl https支持

]# yum install gcc-c++
]# yum -y install pcre*
]# yum -y install openssl*

查看依赖类库安装情况

]# rpm -qa  gcc-c++
gcc-c++-4.4.7-18.el6_9.2.x86_64

]# rpm -qa  pcre*
pcre-static-7.8-7.el6.x86_64
pcre-7.8-7.el6.x86_64
pcre-devel-7.8-7.el6.x86_64

]# rpm -qa  openssl*
openssl098e-0.9.8e-20.el6.centos.1.x86_64
openssl-perl-1.0.1e-57.el6.x86_64
openssl-1.0.1e-57.el6.x86_64
openssl-devel-1.0.1e-57.el6.x86_64
openssl-static-1.0.1e-57.el6.x86_64

安装nginx

]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
]# tar -xzvf nginx-1.12.2.tar.gz 
]# cd nginx-1.12.2
#设置安装目录为 /usr/local/src/nginx 
#设置支持https
]# ./configure --prefix=/usr/local/src/nginx --with-http_ssl_module
./configure

执行./configure *** 命令后终端上会有些输出
输出的信息里会包含依赖的组件是否完整,如果不完整则需要另行安装
输出的信息里会包含配置文件目录信息,日志文件目录信息等一些很重要的我们做运维依赖的信息

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/src/nginx"
  nginx binary file: "/usr/local/src/nginx/sbin/nginx"
  nginx modules path: "/usr/local/src/nginx/modules"
  nginx configuration prefix: "/usr/local/src/nginx/conf"
  nginx configuration file: "/usr/local/src/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/src/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/src/nginx/logs/error.log"
  nginx http access log file: "/usr/local/src/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"
make
]# make
#省略若干行
sed -e "s|%%PREFIX%%|/usr/local/src/nginx|" \
        -e "s|%%PID_PATH%%|/usr/local/src/nginx/logs/nginx.pid|" \
        -e "s|%%CONF_PATH%%|/usr/local/src/nginx/conf/nginx.conf|" \
        -e "s|%%ERROR_LOG_PATH%%|/usr/local/src/nginx/logs/error.log|" \
        < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/soft/nginx-1.12.2'
make install
]# make install

配置环境变量
]# vim /etc/profile

#set nginx environment
export NGINX_HOME=/usr/local/src/nginx
export PATH=${NGINX_HOME}/sbin:$PATH

]# source /etc/profile
nginx 命令行
]# nginx -h
nginx version: nginx/1.12.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/src/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file
]# nginx
]# nginx -s reload
]# nginx -s stop
]# nginx -s reload
]# nginx -s stop

或者 查进程号之后 kill -9 pid

nginx 安装验证
]# ps -ef | grep nginx
root      1253     1  0 10:54 ?        00:00:00 nginx: master process ./nginx
nobody    1254  1253  0 10:54 ?        00:00:00 nginx: worker process
root      1267 56707  0 10:54 pts/4    00:00:00 grep nginx

可以看到nginx的master和worker进程

启动nginx后可以通过主机名或者ip进行访问验证
http://master/
http://192.168.40.130/


看到以上页面则证明nginx安装成功
上一篇下一篇

猜你喜欢

热点阅读