Nginx 是一款轻量级的 Web 服务器/反向代理服务器,比较流行,建议在 Linux 下安装运行。html
它们包括:gcc,openssl,zlib,pcre(可经过rpm -q命令查询是否已安装),已安装则跳过nginx
Nginx
的编译环境 gcc
yum install gcc-c++
nginx
的 http
模块使用 pcre
解析正则表达式,因此安装 perl
兼容的正则表达式库yum install -y pcre pcre-devel
nginx
使用 zlib
对 http
包的内容进行 gzip
yum install -y zlib zlib-devel
nginx
不只支持 http
协议,还支持 https
(即在 ssl
协议上传输 http
),若是使用了 https
,须要安装 OpenSSL
库yum install -y openssl openssl-devel
1.直接下载.tar.gz
安装包,地址:https://nginx.org/en/download.html正则表达式
2.使用wget
命令下载(推荐放在 /usr/local路径下)swift
wget -c https://nginx.org/download/nginx-1.12.2.tar.gz
我下载的是1.12.2版本,这个是目前的稳定版。
vim
tar -zxvf nginx-1.12.2.tar.gz
进入 解压后的目录
cd /usr/local/nginx-1.12.2
cd /usr/local/nginx-1.12.2
1.使用默认配置ruby
./configurebash
2.自定义配置(不推荐)服务器
./configure \
--prefix=/usr/local/nginx \ --conf-path=/usr/local/nginx/conf/nginx.conf \ --pid-path=/usr/local/nginx/conf/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
注意:使用默认配置时,nginx
被安装到 /usr/local/nginx
下。测试
make
make install
whereis nginx

vim /etc/profile
在合适位置添加环境变量ui
export NGINX_HOME=/usr/local/nginx export PATH=$PATH:$NGINX_HOME/sbin
使配置生效
source /etc/profile
由于将 Nginx
配置到了环境变量中,所以,在任何路径下均可以直接使用 nginx
命令,而不须要进入 nginx
路径下执行。
若是没有配置环境变量,则须要先进入 cd /usr/local/nginx/sbin
nginx
cd /usr/local/nginx/sbin
./nginx
ps -ef | grep nginx

nginx
./nginx -s stop:此方式至关于先查出nginx进程id再使用kill命令强制杀掉进程。
./nginx -s quit:此方式中止步骤是待nginx进程处理任务完毕进行中止。
./nginx -s stop
./nginx -s quit
nginx
1.先中止再启动(推荐):
对 nginx 进行重启至关于先中止再启动,即先执行中止命令再执行启动命令。以下:
./nginx -s quit ./nginx
2.修改配置文件,从新加载配置文件:
当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效须要重启 nginx,使用-s reload
不用先中止 ngin x再启动 nginx 便可将配置信息在 nginx 中生效,以下:
./nginx -s reload
一般能够经过这个命令查看 nginx
配置文件的位置
./nginx -t

即在rc.local
增长启动代码就能够了。
vi /etc/rc.local
增长一行 /usr/local/nginx/sbin/nginx
设置执行权限:
chmod 755 rc.local
nginx -c /usr/local/nginx/conf/nginx.conf
参考文章:https://blog.csdn.net/qq_30038111/article/details/79410354