Nginx 是 C语言 开发,建议在 Linux 上运行,固然,也能够安装 Windows 版本,本篇则使用 CentOS 7 做为安装环境。html
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、经常使用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不只支持 http 协议,还支持 https(即在ssl协议上传输http),因此须要在 Centos 安装 OpenSSL 库。
yum install -y openssl openssl-devel
linux
直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html
nginx
使用wget命令下载(推荐)
wget -c https://nginx.org/download/nginx-1.15.0.tar.gz
c++
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
其实在 nginx-1.10.1 版本中你就不须要去配置相关东西,默认就能够了。固然,若是你要本身配置目录也是能够的。正则表达式
./configure
./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
注:将临时文件目录指定为/var/temp/nginx,须要在/var下建立temp及nginx目录
make
make install
查找安装路径:算法
whereis nginx
cd /usr/local/nginx/sbin/
./nginx ./nginx -s stop ./nginx -s quit ./nginx -s reload
./nginx -s quit:此方式中止步骤是待nginx进程处理任务完毕进行中止。 ./nginx -s stop:此方式至关于先查出nginx进程id再使用kill命令强制杀掉进程。
查询nginx进程:浏览器
ps aux|grep nginx
对 nginx 进行重启至关于先中止再启动,即先执行中止命令再执行启动命令。以下:安全
./nginx -s quit ./nginx
当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效须要重启 nginx,使用-s reload不用先中止 ngin x再启动 nginx 便可将配置信息在 nginx 中生效,以下:测试
./nginx -s reload
启动成功后,在浏览器能够看到这样的页面:
ui
开机自启动
即在rc.local增长启动代码就能够了。
vi /etc/rc.local
增长一行 /usr/local/nginx/sbin/nginx
设置执行权限:
chmod 755 rc.local