一般nginx都会用来作反向代理服务器。用来转发80(http协议)和443(https协议)端口
而低于1024端口一般是root才能使用的。因此这里配置和启动都以root来运行。
- 安装依赖的包
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
- 下载解压
cd /usr/local
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar -zxvf nginx-1.14.2.tar.gz
- 编译安装
mkdir -p /var/log/nginx/
mkdir -p /var/temp/nginx/
cd nginx-1.14.2
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
make
make install
- 命令相关
ln -s /usr/bin/nginx /usr/local/nginx/sbin/nginx
命令 | 说明 |
---|
nginx -t | 验证nginx配置文件是否正确 |
nginx | 启动neingx 默认使用 安装目录/conf/nginx.conf 配置文件 |
nginx -c /usr/local/nginx/conf/nginx.conf | 使用 -c 指定配置文件 |
nginx -s reload | 重启nginx |
nginx -s quit | 停止nginx |