一、安装依赖
prce(重定向支持)和openssl(https支持,如果不需要https可以不安装。)
yum install -y pcre-devel
yum -y install gcc make gcc-c++ wget
yum -y install openssl openssl-devel
二、下载
wget http://nginx.org/download/nginx-1.8.0.tar.gz
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
三、编译安装
1、然后进入目录编译安装,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"
关于上面的参数可以使用nginx -V
来查看。
2、安装报错误的话比如:“C compiler cc is not found”,这个就是缺少编译环境,安装一下就可以了
yum -y install gcc make gcc-c++ openssl-devel
3、如果没有error信息,就可以执行下边的安装了:
make
make install
四、Nginx测试
1、运行下面命令会出现两个结果,一般情况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
2、设置全局nginx命令
vi ~/.bash_profile
3、将下面内容添加到 ~/.bash_profile
文件中
PATH=$PATH:$HOME/bin:/usr/local/nginx/sbin/
export PATH
4、运行命令source ~/.bash_profile
让配置立即生效。你就可以全局运行 nginx 命令了。
五、使用命令行安装
1、 在ubuntu系统下。
$ sudo apt-get install nginx
2 、在CentOS系统下。
sudo yum install nginx
3、在mac下,可以使用brew安装。
$ brew install nginx