安装
安装依赖
prce(重定向支持)和openssl(https支持,如果不需要https可以不安装。)
yum install -y pcre-devel
yum -y install gcc make gcc-c++ wget
yum -y install openssl openssl-devel
CentOS 6.5 我安装的时候是选择的“基本服务器”,默认这两个包都没安装全,所以这两个都运行安装即可。
下载
wget http://nginx.org/download/nginx-1.13.3.tar.gz
wget http://nginx.org/download/nginx-1.13.7.tar.gz
# 如果没有安装wget
# 下载已编译版本
$ yum install wget
# 解压压缩包
tar zxf nginx-1.13.3.tar.gz
编译安装
然后进入目录编译安装,configure参数说明
cd nginx-1.11.5
./configure
....
Configuration summary
+ using system PCRE library
+ 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"
安装报错误的话比如:“C compiler cc is not found”,这个就是缺少编译环境,安装一下就可以了 yum -y install gcc make gcc-c++ openssl-devel
如果没有error信息,就可以执行下边的安装了:
make
make install
nginx测试
运行下面命令会出现两个结果,一般情况nginx会安装在/usr/local/nginx
目录中
cd /usr/local/nginx/sbin/
./nginx -t
# nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
# nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
设置全局nginx命令
vi ~/.bash_profile
将下面内容添加到 ~/.bash_profile
文件中
PATH=$PATH:$HOME/bin:/usr/local/nginx/sbin/
export PATH
运行命令 source ~/.bash_profile
让配置立即生效。你就可以全局运行 nginx
命令了。